#include <bits/stdc++.h>
#define filenamej "BRCKTS"
#define N 1000001
#define FOR(i, a, b) for(int i = a; i <= b; i++)
#define endl "\n"
using namespace std;
int nn, n, m, u, v, t;
char a[N];
char ch;
struct lalala { int l = 0; int r = 0; int wopen = 0; int wclose = 0; } node[4 * N];
int leaf[N];
inline void combine(int i)
{
int dec = min(node[i * 2].wopen, node[i * 2 + 1].wclose);
node[i].wopen = node[i * 2].wopen - dec + node[i * 2 + 1].wopen;
node[i].wclose = node[i * 2 + 1].wclose - dec + node[i * 2].wclose;
}
void initLR(int i, int x, int y)
{
// cout << i << ": " << x << " " << y << endl;
node[i].l = x;
node[i].r = y;
if (x == y)
{
leaf[x] = i;
return;
}
int mi = (x + y) / 2;
initLR(i * 2, x, mi);
initLR(i * 2 + 1, mi + 1, y);
}
void build(int i)
{
if (node[i].l == node[i].r)
{
int vtr = node[i].l;
if (a[vtr] == '(') node[i].wopen = 1;
else node[i].wclose = 1;
return;
}
build(i * 2);
build(i * 2 + 1);
combine(i);
}
void update(int i)
{
a[i] = ch;
int j = leaf[i];
if (ch == '(')
{
node[j].wopen = 1;
node[j].wclose = 0;
}
else
{
node[j].wclose = 1;
node[j].wopen = 0;
}
j /= 2;
for(; j > 0; j /= 2) combine(j);
}
lalala query(int i)
{
if (node[i].r < u || node[i].l > v) return node[0]; // default
if (node[i].r <= v && node[i].l >= u) return node[i];
lalala q1 = query(i * 2);
lalala q2 = query(i * 2 + 1);
int dec = min(q1.wopen, q2.wclose);
lalala res;
res.wopen = q1.wopen - dec + q2.wopen;
res.wclose = q2.wclose - dec + q1.wclose;
return res;
}
int main()
{
#ifdef filename
freopen(filename".inp", "r", stdin);
freopen(filename".out", "w", stdout);
#endif // filename
int tes = 0;
while (true)
{
tes++;
n = -1;
cin >> n;
if (n == -1) return 0;
cout << "Test " << tes << ":\n";
initLR(1, 1, n);
u = 1;
v = n;
FOR(i, 1, n) cin >> a[i];
build(1);
cin >> m;
FOR(i, 1, m)
{
cin >> t;
if (t == 0)
{
lalala ans = query(1);
if (ans.wopen == 0 && ans.wclose == 0) cout << "YES\n";
else cout << "NO\n";
}
else
{
ch = (a[t] == '(') ? ')' : '(';
update(t);
}
}
}
return 0;
}
I2luY2x1ZGUgPGJpdHMvc3RkYysrLmg+CiNkZWZpbmUgZmlsZW5hbWVqICJCUkNLVFMiCiNkZWZpbmUgTiAxMDAwMDAxCiNkZWZpbmUgRk9SKGksIGEsIGIpIGZvcihpbnQgaSA9IGE7IGkgPD0gYjsgaSsrKQojZGVmaW5lIGVuZGwgIlxuIgp1c2luZyBuYW1lc3BhY2Ugc3RkOwoKaW50IG5uLCBuLCBtLCB1LCB2LCB0OwpjaGFyIGFbTl07CmNoYXIgY2g7CnN0cnVjdCBsYWxhbGEgeyBpbnQgbCA9IDA7IGludCByID0gMDsgaW50IHdvcGVuID0gMDsgaW50IHdjbG9zZSA9IDA7IH0gbm9kZVs0ICogTl07CmludCBsZWFmW05dOwoKaW5saW5lIHZvaWQgY29tYmluZShpbnQgaSkKewogICAgaW50IGRlYyA9IG1pbihub2RlW2kgKiAyXS53b3Blbiwgbm9kZVtpICogMiArIDFdLndjbG9zZSk7CiAgICBub2RlW2ldLndvcGVuID0gbm9kZVtpICogMl0ud29wZW4gLSBkZWMgKyBub2RlW2kgKiAyICsgMV0ud29wZW47CiAgICBub2RlW2ldLndjbG9zZSA9IG5vZGVbaSAqIDIgKyAxXS53Y2xvc2UgLSBkZWMgKyBub2RlW2kgKiAyXS53Y2xvc2U7Cn0KCnZvaWQgaW5pdExSKGludCBpLCBpbnQgeCwgaW50IHkpCnsKLy8gICAgY291dCA8PCBpIDw8ICI6ICIgPDwgeCA8PCAiICIgPDwgeSA8PCBlbmRsOwogICAgbm9kZVtpXS5sID0geDsKICAgIG5vZGVbaV0uciA9IHk7CiAgICBpZiAoeCA9PSB5KQogICAgewogICAgICAgIGxlYWZbeF0gPSBpOwogICAgICAgIHJldHVybjsKICAgIH0KICAgIGludCBtaSA9ICh4ICsgeSkgLyAyOwogICAgaW5pdExSKGkgKiAyLCB4LCBtaSk7CiAgICBpbml0TFIoaSAqIDIgKyAxLCBtaSArIDEsIHkpOwp9Cgp2b2lkIGJ1aWxkKGludCBpKQp7CiAgICBpZiAobm9kZVtpXS5sID09IG5vZGVbaV0ucikKICAgIHsKICAgICAgICBpbnQgdnRyID0gbm9kZVtpXS5sOwogICAgICAgIGlmIChhW3Z0cl0gPT0gJygnKSBub2RlW2ldLndvcGVuID0gMTsKICAgICAgICBlbHNlIG5vZGVbaV0ud2Nsb3NlID0gMTsKICAgICAgICByZXR1cm47CiAgICB9CiAgICBidWlsZChpICogMik7CiAgICBidWlsZChpICogMiArIDEpOwogICAgY29tYmluZShpKTsKfQoKdm9pZCB1cGRhdGUoaW50IGkpCnsKICAgIGFbaV0gPSBjaDsKICAgIGludCBqID0gbGVhZltpXTsKICAgIGlmIChjaCA9PSAnKCcpCiAgICB7CiAgICAgICAgbm9kZVtqXS53b3BlbiA9IDE7CiAgICAgICAgbm9kZVtqXS53Y2xvc2UgPSAwOwogICAgfQogICAgZWxzZQogICAgewogICAgICAgIG5vZGVbal0ud2Nsb3NlID0gMTsKICAgICAgICBub2RlW2pdLndvcGVuID0gMDsKICAgIH0KICAgIGogLz0gMjsKICAgIGZvcig7IGogPiAwOyBqIC89IDIpIGNvbWJpbmUoaik7Cn0KCmxhbGFsYSBxdWVyeShpbnQgaSkKewogICAgaWYgKG5vZGVbaV0uciA8IHUgfHwgbm9kZVtpXS5sID4gdikgcmV0dXJuIG5vZGVbMF07IC8vIGRlZmF1bHQKICAgIGlmIChub2RlW2ldLnIgPD0gdiAmJiBub2RlW2ldLmwgPj0gdSkgcmV0dXJuIG5vZGVbaV07CiAgICBsYWxhbGEgcTEgPSBxdWVyeShpICogMik7CiAgICBsYWxhbGEgcTIgPSBxdWVyeShpICogMiArIDEpOwogICAgaW50IGRlYyA9IG1pbihxMS53b3BlbiwgcTIud2Nsb3NlKTsKICAgIGxhbGFsYSByZXM7CiAgICByZXMud29wZW4gPSBxMS53b3BlbiAtIGRlYyArIHEyLndvcGVuOwogICAgcmVzLndjbG9zZSA9IHEyLndjbG9zZSAtIGRlYyArIHExLndjbG9zZTsKICAgIHJldHVybiByZXM7Cn0KCmludCBtYWluKCkKewoJI2lmZGVmIGZpbGVuYW1lCgkJZnJlb3BlbihmaWxlbmFtZSIuaW5wIiwgInIiLCBzdGRpbik7CgkJZnJlb3BlbihmaWxlbmFtZSIub3V0IiwgInciLCBzdGRvdXQpOwoJI2VuZGlmIC8vIGZpbGVuYW1lCgogICAgaW50IHRlcyA9IDA7CiAgICB3aGlsZSAodHJ1ZSkKICAgIHsKICAgICAgICB0ZXMrKzsKICAgICAgICBuID0gLTE7CiAgICAgICAgY2luID4+IG47CiAgICAgICAgaWYgKG4gPT0gLTEpIHJldHVybiAwOwogICAgICAgIGNvdXQgPDwgIlRlc3QgIiA8PCB0ZXMgPDwgIjpcbiI7CiAgICAgICAgaW5pdExSKDEsIDEsIG4pOwogICAgICAgIHUgPSAxOwogICAgICAgIHYgPSBuOwogICAgICAgIEZPUihpLCAxLCBuKSBjaW4gPj4gYVtpXTsKICAgICAgICBidWlsZCgxKTsKICAgICAgICBjaW4gPj4gbTsKICAgICAgICBGT1IoaSwgMSwgbSkKICAgICAgICB7CiAgICAgICAgICAgIGNpbiA+PiB0OwogICAgICAgICAgICBpZiAodCA9PSAwKQogICAgICAgICAgICB7CiAgICAgICAgICAgICAgICBsYWxhbGEgYW5zID0gcXVlcnkoMSk7CiAgICAgICAgICAgICAgICBpZiAoYW5zLndvcGVuID09IDAgJiYgYW5zLndjbG9zZSA9PSAwKSBjb3V0IDw8ICJZRVNcbiI7CiAgICAgICAgICAgICAgICBlbHNlIGNvdXQgPDwgIk5PXG4iOwogICAgICAgICAgICB9CiAgICAgICAgICAgIGVsc2UKICAgICAgICAgICAgewogICAgICAgICAgICAgICAgY2ggPSAoYVt0XSA9PSAnKCcpID8gJyknIDogJygnOwogICAgICAgICAgICAgICAgdXBkYXRlKHQpOwogICAgICAgICAgICB9CiAgICAgICAgfQogICAgfQoKCXJldHVybiAwOwp9Cg==