#include <bits/stdc++.h>
using namespace std;
// make sure modify 0LL + , 1LL * , overflow when remove define
#define int long long
#define _3bkarm cin.tie(NULL); cout.tie(NULL); ios::sync_with_stdio(false);
struct BIT {
int n;
vector<int> tree;
void init(int _n) {
n = _n, tree.assign(_n, 0);
}
void add(int at, int value) {
for (int i = at + 1; i <= n; i += i & -i)
tree[i - 1] += value;
}
int sum(int exc) {
int ans = 0;
for (int i = exc; i > 0; i -= i & -i)
ans += tree[i - 1];
return ans;
}
int sum(int inc, int exc) {
return sum(exc) - sum(inc);
}
int search(int value) {
int sum = 0, pos = -1;
// decrease
for (int i = 25; i >= 0; --i) {
if (pos + (1 << i) < n and sum + tree[pos + (1 << i)] < value)
sum += tree[pos + (1 << i)], pos += (1 << i);
}
// pos : less than val
return pos + 1;
}
};
vector<vector<int>> adj;
int ct = 0;
vector<bool> vis;
vector<int> in, out;
void dfs(int u) {
vis[u] = true;
in[u] = ct++;
for (int ch : adj[u])
dfs(ch);
out[u] = ct;
}
void get_shit_done() {
int n, q;
cin >> n >> q;
string s;
cin >> s;
vector<int> a(2 * n);
for (int i = 0; i < 2 * n; ++i)
cin >> a[i];
adj.assign(2 * n, {});
vector<int> close(2 * n), t;
for (int i = 0; i < 2 * n; ++i) {
if (s[i] == '(') {
if ( not t.empty() )
adj[t.back()].push_back(i);
t.push_back(i);
} else {
close[t.back()] = i;
t.pop_back();
}
}
BIT tree;
tree.init(2 * n + 1);
ct = 0;
in.assign(2 * n, 0);
out.assign(2 * n, 0);
vis.assign(2 * n, false);
for (int i = 0; i < 2 * n; ++i) {
if (not vis[i] and s[i] == '(')
dfs(i);
}
while (q--) {
int op;
cin >> op;
if (op == 1) {
int l1, r1, l2, r2, x;
cin >> l1 >> r1 >> l2 >> r2 >> x;
--l1, --r1, --l2, --r2;
if (l1 > l2) {
swap(l1, l2);
swap(r1, r2);
}
if ( l2 < r1 )
tree.add(in[l1], x);
else
tree.add(in[l2], x);
} else {
int l, r;
cin >> l >> r;
--l, --r;
cout << a[l] + tree.sum(in[l], out[l]) << '\n';
}
}
}
signed main() {
_3bkarm
int ts = 1;
cin >> ts;
while (ts--) {
get_shit_done();
}
return 0;
}
I2luY2x1ZGUgPGJpdHMvc3RkYysrLmg+Cgp1c2luZyBuYW1lc3BhY2Ugc3RkOwoKLy8gbWFrZSBzdXJlIG1vZGlmeSAwTEwgKyAsIDFMTCAqICwgb3ZlcmZsb3cgd2hlbiByZW1vdmUgZGVmaW5lCiNkZWZpbmUgaW50IGxvbmcgbG9uZwojZGVmaW5lIF8zYmthcm0gY2luLnRpZShOVUxMKTsgY291dC50aWUoTlVMTCk7IGlvczo6c3luY193aXRoX3N0ZGlvKGZhbHNlKTsKCnN0cnVjdCBCSVQgewogICAgaW50IG47CiAgICB2ZWN0b3I8aW50PiB0cmVlOwoKICAgIHZvaWQgaW5pdChpbnQgX24pIHsKICAgICAgICBuID0gX24sIHRyZWUuYXNzaWduKF9uLCAwKTsKICAgIH0KCiAgICB2b2lkIGFkZChpbnQgYXQsIGludCB2YWx1ZSkgewogICAgICAgIGZvciAoaW50IGkgPSBhdCArIDE7IGkgPD0gbjsgaSArPSBpICYgLWkpCiAgICAgICAgICAgIHRyZWVbaSAtIDFdICs9IHZhbHVlOwogICAgfQoKICAgIGludCBzdW0oaW50IGV4YykgewogICAgICAgIGludCBhbnMgPSAwOwogICAgICAgIGZvciAoaW50IGkgPSBleGM7IGkgPiAwOyBpIC09IGkgJiAtaSkKICAgICAgICAgICAgYW5zICs9IHRyZWVbaSAtIDFdOwogICAgICAgIHJldHVybiBhbnM7CiAgICB9CgogICAgaW50IHN1bShpbnQgaW5jLCBpbnQgZXhjKSB7CiAgICAgICAgcmV0dXJuIHN1bShleGMpIC0gc3VtKGluYyk7CiAgICB9CgogICAgaW50IHNlYXJjaChpbnQgdmFsdWUpIHsKICAgICAgICBpbnQgc3VtID0gMCwgcG9zID0gLTE7CiAgICAgICAgLy8gZGVjcmVhc2UKICAgICAgICBmb3IgKGludCBpID0gMjU7IGkgPj0gMDsgLS1pKSB7CiAgICAgICAgICAgIGlmIChwb3MgKyAoMSA8PCBpKSA8IG4gYW5kIHN1bSArIHRyZWVbcG9zICsgKDEgPDwgaSldIDwgdmFsdWUpCiAgICAgICAgICAgICAgICBzdW0gKz0gdHJlZVtwb3MgKyAoMSA8PCBpKV0sIHBvcyArPSAoMSA8PCBpKTsKICAgICAgICB9CiAgICAgICAgLy8gcG9zIDogbGVzcyB0aGFuIHZhbAogICAgICAgIHJldHVybiBwb3MgKyAxOwogICAgfQp9OwoKdmVjdG9yPHZlY3RvcjxpbnQ+PiBhZGo7CgppbnQgY3QgPSAwOwp2ZWN0b3I8Ym9vbD4gdmlzOwp2ZWN0b3I8aW50PiBpbiwgb3V0Owp2b2lkIGRmcyhpbnQgdSkgewogICAgdmlzW3VdID0gdHJ1ZTsKICAgIGluW3VdID0gY3QrKzsKICAgIGZvciAoaW50IGNoIDogYWRqW3VdKQogICAgICAgIGRmcyhjaCk7CiAgICBvdXRbdV0gPSBjdDsKfQoKdm9pZCBnZXRfc2hpdF9kb25lKCkgewogICAgaW50IG4sIHE7CiAgICBjaW4gPj4gbiA+PiBxOwoKICAgIHN0cmluZyBzOwogICAgY2luID4+IHM7CgogICAgdmVjdG9yPGludD4gYSgyICogbik7CiAgICBmb3IgKGludCBpID0gMDsgaSA8IDIgKiBuOyArK2kpCiAgICAgICAgY2luID4+IGFbaV07CgogICAgYWRqLmFzc2lnbigyICogbiwge30pOwogICAgdmVjdG9yPGludD4gY2xvc2UoMiAqIG4pLCB0OwogICAgZm9yIChpbnQgaSA9IDA7IGkgPCAyICogbjsgKytpKSB7CiAgICAgICAgaWYgKHNbaV0gPT0gJygnKSB7CiAgICAgICAgICAgIGlmICggbm90IHQuZW1wdHkoKSApCiAgICAgICAgICAgICAgICBhZGpbdC5iYWNrKCldLnB1c2hfYmFjayhpKTsKICAgICAgICAgICAgdC5wdXNoX2JhY2soaSk7CiAgICAgICAgfSBlbHNlIHsKICAgICAgICAgICAgY2xvc2VbdC5iYWNrKCldID0gaTsKICAgICAgICAgICAgdC5wb3BfYmFjaygpOwogICAgICAgIH0KICAgIH0KCiAgICBCSVQgdHJlZTsKICAgIHRyZWUuaW5pdCgyICogbiArIDEpOwoKICAgIGN0ID0gMDsKICAgIGluLmFzc2lnbigyICogbiwgMCk7CiAgICBvdXQuYXNzaWduKDIgKiBuLCAwKTsKICAgIHZpcy5hc3NpZ24oMiAqIG4sIGZhbHNlKTsKICAgIGZvciAoaW50IGkgPSAwOyBpIDwgMiAqIG47ICsraSkgewogICAgICAgIGlmIChub3QgdmlzW2ldIGFuZCBzW2ldID09ICcoJykKICAgICAgICAgICAgZGZzKGkpOwogICAgfQoKICAgIHdoaWxlIChxLS0pIHsKICAgICAgICBpbnQgb3A7CiAgICAgICAgY2luID4+IG9wOwogICAgICAgIGlmIChvcCA9PSAxKSB7CiAgICAgICAgICAgIGludCBsMSwgcjEsIGwyLCByMiwgeDsKICAgICAgICAgICAgY2luID4+IGwxID4+IHIxID4+IGwyID4+IHIyID4+IHg7CiAgICAgICAgICAgIC0tbDEsIC0tcjEsIC0tbDIsIC0tcjI7CiAgICAgICAgICAgIGlmIChsMSA+IGwyKSB7CiAgICAgICAgICAgICAgICBzd2FwKGwxLCBsMik7CiAgICAgICAgICAgICAgICBzd2FwKHIxLCByMik7CiAgICAgICAgICAgIH0KICAgICAgICAgICAgaWYgKCBsMiA8IHIxICkKICAgICAgICAgICAgICAgIHRyZWUuYWRkKGluW2wxXSwgeCk7CiAgICAgICAgICAgIGVsc2UKICAgICAgICAgICAgICAgIHRyZWUuYWRkKGluW2wyXSwgeCk7CiAgICAgICAgfSBlbHNlIHsKICAgICAgICAgICAgaW50IGwsIHI7CiAgICAgICAgICAgIGNpbiA+PiBsID4+IHI7CiAgICAgICAgICAgIC0tbCwgLS1yOwogICAgICAgICAgICBjb3V0IDw8IGFbbF0gKyB0cmVlLnN1bShpbltsXSwgb3V0W2xdKSA8PCAnXG4nOwogICAgICAgIH0KICAgIH0KfQoKc2lnbmVkIG1haW4oKSB7CiAgICBfM2JrYXJtCgogICAgaW50IHRzID0gMTsKICAgIGNpbiA+PiB0czsKICAgIHdoaWxlICh0cy0tKSB7CiAgICAgICAgZ2V0X3NoaXRfZG9uZSgpOwogICAgfQoKICAgIHJldHVybiAwOwp9