#include <iostream>
#include <vector>
#include <set>
using namespace std;
void solve() {
int t;
cin >> t;
while (t--) {
int n, m, k;
cin >> n >> m >> k;
vector<int> a(m);
for (int i = 0; i < m; ++i) {
cin >> a[i];
}
set<int> knownQuestions;
for (int i = 0; i < k; ++i) {
int q;
cin >> q;
knownQuestions.insert(q);
}
if(n >= k+2){
for(int i = 0; i < m; i++){
cout << 0;
}
}
else if(n <= k){
for(int i = 0; i < m; i++){
cout << 1;
}
}
else{
string result;
for (int i = 0; i < m; ++i) {
if (knownQuestions.size() == n - 1 && knownQuestions.count(a[i]) == 0) {
result += '1';
} else {
result += '0';
}
}
cout << result;
}
cout <<"\n";
}
}
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
solve();
return 0;
}
I2luY2x1ZGUgPGlvc3RyZWFtPgojaW5jbHVkZSA8dmVjdG9yPgojaW5jbHVkZSA8c2V0Pgp1c2luZyBuYW1lc3BhY2Ugc3RkOwoKdm9pZCBzb2x2ZSgpIHsKICAgIGludCB0OwogICAgY2luID4+IHQ7CiAgICB3aGlsZSAodC0tKSB7CiAgICAgICAgaW50IG4sIG0sIGs7CiAgICAgICAgY2luID4+IG4gPj4gbSA+PiBrOwoKICAgICAgICB2ZWN0b3I8aW50PiBhKG0pOwogICAgICAgIGZvciAoaW50IGkgPSAwOyBpIDwgbTsgKytpKSB7CiAgICAgICAgICAgIGNpbiA+PiBhW2ldOwogICAgICAgIH0KCiAgICAgICAgc2V0PGludD4ga25vd25RdWVzdGlvbnM7CiAgICAgICAgZm9yIChpbnQgaSA9IDA7IGkgPCBrOyArK2kpIHsKICAgICAgICAgICAgaW50IHE7CiAgICAgICAgICAgIGNpbiA+PiBxOwogICAgICAgICAgICBrbm93blF1ZXN0aW9ucy5pbnNlcnQocSk7CiAgICAgICAgfQoJCQoJCWlmKG4gPj0gaysyKXsKCQkJZm9yKGludCBpID0gMDsgaSA8IG07IGkrKyl7CgkJCQljb3V0IDw8IDA7CgkJCX0KCQl9CgkJZWxzZSBpZihuIDw9IGspewoJCQlmb3IoaW50IGkgPSAwOyBpIDwgbTsgaSsrKXsKCQkJCWNvdXQgPDwgMTsKCQkJfQoJCX0KCQllbHNlewogICAgICAgIHN0cmluZyByZXN1bHQ7CiAgICAgICAgZm9yIChpbnQgaSA9IDA7IGkgPCBtOyArK2kpIHsKICAgICAgICAgICAgaWYgKGtub3duUXVlc3Rpb25zLnNpemUoKSA9PSBuIC0gMSAmJiBrbm93blF1ZXN0aW9ucy5jb3VudChhW2ldKSA9PSAwKSB7CiAgICAgICAgICAgICAgICByZXN1bHQgKz0gJzEnOwogICAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICAgICAgcmVzdWx0ICs9ICcwJzsKICAgICAgICAgICAgfQogICAgICAgIH0KCiAgICAgICAgY291dCA8PCByZXN1bHQ7CgkJfQoJCWNvdXQgPDwiXG4iOwogICAgfQp9CgppbnQgbWFpbigpIHsKICAgIGlvczo6c3luY193aXRoX3N0ZGlvKGZhbHNlKTsKICAgIGNpbi50aWUobnVsbHB0cik7CgogICAgc29sdmUoKTsKICAgIHJldHVybiAwOwp9Cg==