#include <bits/stdc++.h>
#define MAX 1000
using namespace std;
int main(){
int m,n;
int v[MAX],index[MAX];
set<int> s1; //去重排序用
set<int> s2;
map<int,int> mp; //map记录对应值的数量
cin>>m;
while(m--){
cin>>n;
for(int i = 0; i < n; i++)
cin>>v[i];
for(int i = 0; i < n; i++)
cin>>index[i];
for(int i = 0; i < n; i++){
s1.insert(index[i]); //对组数去重、并从小到大排序
s2.insert(v[i]); //对内容去重、并从小到大排序
}
for(set<int>::iterator i = s1.begin();i != s1.end(); i++){ //组数
for(set<int>::iterator j = s2.begin();j != s2.end(); j++){ //初始化内容个数
mp[*j] = 0;
}
for(int j = 0; j < n; j++){ //遍历数组给map赋值个数
if(index[j] == *i){
mp[v[j]]++;
}
}
cout<<*i<<"={";
map<int,int>::iterator it;
for(it = mp.begin(); it != --mp.end(); it++){ //输出到倒数第二个数
cout<<it->first<<"="<<it->second<<",";
}
cout<<it->first<<"="<<it->second<<"}"<<endl; //单独处理最后一个数
}
mp.clear(); //重置map
s1.clear();
s2.clear();
}
}