#include<iostream>
using namespace std;
#define INF -99
int main()
{
int t;
cin >> t;
while( t-- ){
int m, n;
cin >> m >> n;
int * a = new int[m];
for( int i=0; i<m; i++) a[i] = INF;
// 建表
while( n-- ){
int num ;
cin >> num;
int di = 1;
int h = num%11;
if(a[h]==INF){
a[h] = num;
continue;
}
while( true ){
int temp = (h+di)%m;
if( a[temp] == INF ){
a[temp] = num;
break;
} else{
di++;
}
}
}
for(int i=0; i<m; i++){
if(a[i] == INF ) cout<<"NULL"<<" ";
else cout<<a[i]<<" ";
}
cout << endl;
int k;
cin >> k;
while(k--) {
int f;
cin >> f;
int h = f%11;
int times = 1;
int flag = 0;
int tf = 0;
int temp = h;
/**************
* 查找分三种情况:
* 1. 要找的关键字的hash地址为空
* 2. 要找的关键字的hash地址不为空且等于关键字
* 3. 要找的关键字的hash地址不为空,也不等于关键字,则进行线性探测
*
*
* **********/
if(a[h]==INF){ // 第一种情况
cout<<0<<" "<<1<<endl;
}
else{
if( a[h]==f ){ // 第二种情况
cout<< 1 << " " << 1 << " " << h+1 <<endl;
continue;
}
while(true){ // 第三种情况
int temp = ( h+times ) %m;
times++;
if( a[temp]==f ){
cout<<1<<" "<<times<<" "<<temp+1<<endl;
flag = 1;
break;
}
if(a[temp]==INF){
break;
}
}
if( flag==0 ){
cout<<0<<" "<<times<<endl;
}
}
}
}
return 0;
}