#include <iostream>
#include <bits/stdc++.h>
#define ll long long
using namespace std;
ll a[200010],b[200010],ans[200010];
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(nullptr); cout.tie(nullptr);
ll t; cin >> t;
while(t--)
{
ll n,m; cin >> n >> m;
for(ll i=0;i<n;i++)
cin >> a[i]; sort(a,a+n);
for(ll i=0;i<m;i++)
cin >> b[i];
ll maxx=(ll)max_element(a,a+n),win=0;
ll p1=0,p2=0,j=0;
while(p1<=m && p2<m)
{
if(p1==m){ if(a[0]!=a[ans[p2-1]]){ans[p2]=0; p2++; p1=0;} else{ans[p2]=1; p2++; p1=0;} }
else if(b[p2]>maxx){ ans[p2]=0; p2++; p1=0; }
else if(a[p1]>b[p2]){ if(p1!=0 && a[p1]!=a[ans[p2-1]]){ans[p2]=p1; win++; p2++; p1=0;}
else if(p1==0){ if(a[p1]>b[p2])win++; ans[p2]=p1; p2++; p1=0;}
else p1++; }
else p1++;
}
cout << win << "\n";
for(ll i=0;i<m;i++)
cout << ans[i]+1 << " ";
cout << "\n";
}
return 0;
}
Copy