#include<bits/stdc++.h>
#define cin(vec) for(auto& i : vec) cin >> i
#define cout(vec) for(auto& i : vec) cout << i
#define ll long long
#define author_mohamed cin.tie(0)->sync_with_stdio(0);cin.exceptions(cin.failbit);
#define ss short
#define umset unordered_multiset
#define uset unordered_set
#define fx(b) fixed << setprecision(b)
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define vi vector
#define vis vector<string>
#define t int t;cin >> t;while(t--)
#define vi vector
#define st string
#define mod 1000000007
#define mp make_pair
using namespace std;
ll gcd(ll a, ll b) {if (a < b)swap(a, b);while (a != 0 && b != 0) {ll r = a % b;a = b;b = r;}return a;}
ll lcm(ll a, ll b) {return a / gcd(a, b) * b;}
unsigned ll nCr(int n, int r) {if (r > n)return 0;r = max(r, n - r); unsigned ll ans = 1, div = 1, i = r + 1;while (i <= n) {ans *= i;i++;ans /= div;div++;}return ans;}
unsigned ll npr(int n,int r){if(r>n)return 0;unsigned ll a=1,i=n-r+1; while(i<=n){a*=i;i++;}return a;}
int xc[4] = {-1, 1, 0, 0};
int yc[4] = {0, 0, -1, 1};
void solve(){
int n,m;cin>>n>>m;
map<int,int>f;
vi<int>a(n),b(m);
for(int i=0;i<n;i++){
cin>>a[i];
f[a[i]]=i+1;
}
cin(b);
vi<int>x(m);
sort(all(a));
int ans=0;
for(int i=0;i<m;i++){
int d=upper_bound(all(a),b[i])-a.begin();
int c=0;
if(!i){
if(d==n)x[i]=1;
else{
c=f[a[d]];
x[i]=c;
ans++;
}
}
else{
if(d==n){
c=1;
while(x[i-1]==c)c++;
x[i]=c;
}
else{
while(d<n){
c=f[a[d]];
if(x[i-1]!=c){
ans++;x[i]=c;
break;
}
d++;
}
if(d>=n){
d=1;
while(x[i-1]==d)d++;
x[i]=d;
}
}
}
}
cout<<ans<<'\n';
cout(x)<<' ';
cout<<'\n';
}
int main()
{
author_mohamed
//freopen("in.txt", "r", stdin);
//freopen("out.txt", "w", stdout);
t{
solve();
}
return 0;
}
Copy