#include <bits/stdc++.h>
// iostream is too mainstream
#include <cstdio>
// bitch please
#include <iostream>
#include <algorithm>
#include <cstdlib>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <list>
#include <cmath>
#include <iomanip>
#include <time.h>
#define dibs reserve
#define OVER9000 1234567890123456789LL
#define ALL_THE(CAKE,LIE) for(auto LIE =CAKE.begin(); LIE != CAKE.end(); LIE++)
#define tisic 47
#define soclose 1e-8
#define chocolate win
// so much chocolate
#define patkan 9
#define ff first
#define ss second
#define abs(x) ((x < 0)?-(x):x)
#define uint unsigned int
#define dbl long double
#define pi 3.14159265358979323846
using namespace std;
// mylittledoge
typedef long long cat;
#ifdef DONLINE_JUDGE
// palindromic tree is better than splay tree!
#define lld I64d
#endif
struct segtree {
struct node {
int son[2];
int z,k;
int mx,ans;
};
vector<node> T;
int count(int akt, int mx_lft) {
if(T[akt].z == T[akt].k-1) return (T[akt].mx > mx_lft);
node n =T[akt];
if(T[n.son[0]].mx <= mx_lft) return count(n.son[1],mx_lft);
int ret =count(n.son[0],mx_lft);
ret +=T[akt].ans-T[n.son[0]].ans;
return ret;
}
void constT(int akt, vector<int> &A) {
node n =T[akt];
if(n.z == n.k-1) {
T[akt].mx =A[n.z];
return;
}
for(int i =0; i < 2; i++) {
if(i == 0) n.k =(n.z+n.k)/2;
else {n.z =n.k; n.k =T[akt].k;}
T[akt].son[i] =T.size();
T.push_back(n);
constT(T[akt].son[i],A);
}
T[akt].mx =max(T[T[akt].son[0]].mx,T[T[akt].son[1]].mx);
T[akt].ans =T[T[akt].son[0]].ans+count(T[akt].son[1],T[T[akt].son[0]].mx);
}
segtree(int N, vector<int> &A) {
node n;
n.son[0] =n.son[1] =-1;
n.z =0, n.k =N;
n.ans =1;
T.dibs(2*N);
T.resize(1,n);
constT(0,A);
}
void put(int akt, int pos, int val) {
node n =T[akt];
if(n.z > pos || pos >= n.k) return;
if(n.z == pos && n.k == pos+1) {
T[akt].mx +=val;
return;
}
if(pos < (n.z+n.k)/2) put(n.son[0],pos,val);
else put(n.son[1],pos,val);
T[akt].mx =max(T[n.son[0]].mx,T[n.son[1]].mx);
T[akt].ans =T[n.son[0]].ans+count(n.son[1],T[n.son[0]].mx);
}
pair<int,int> get(int akt, int zac, int kon, int mx_lft) {
node n =T[akt];
if(zac >= n.k || n.z >= kon) return make_pair(0,-1);
if(zac == n.z && kon == n.k) return make_pair(count(akt,mx_lft),n.mx);
pair<int,int> ret =get(n.son[0],zac,min(kon,(n.z+n.k)/2),mx_lft);
pair<int,int> ret2 =get(n.son[1],max(zac,(n.z+n.k)/2),kon,max(mx_lft,ret.ss));
ret.ff +=ret2.ff;
ret.ss =max(ret.ss,ret2.ss);
return ret;
}
int get_r_bound(int akt, int l, int R) {
// first index >= R
node n =T[akt];
if(n.mx < R) return n.k;
if(n.z == n.k-1) return n.z;
if(T[n.son[0]].k <= l) return get_r_bound(n.son[1],l,R);
int ret =get_r_bound(n.son[0],l,R);
if(ret < T[n.son[0]].k) return ret;
return get_r_bound(n.son[1],l,R);
}
};
int main() {
cin.sync_with_stdio(0);
cin.tie(0);
cout << fixed << setprecision(10);
int T;
cin >> T;
while(T--) {
int N,Q;
cin >> N >> Q;
vector<int> A(N);
for(int i =0; i < N; i++) cin >> A[i];
segtree I(N,A);
for(int i =0; i < Q; i++) {
string s;
int id;
cin >> s >> id;
id--;
if(s == "+") {
int x;
cin >> x;
I.put(0,id,x);
}
else {
int L,R;
cin >> L >> R;
int h =I.get_r_bound(0,id,R);
cout << I.get(0,id,min(N,h+1),L-1).ff << "\n";
}
}
}
}
// look at my code
// my code is amazing
I2luY2x1ZGUgPGJpdHMvc3RkYysrLmg+Ci8vIGlvc3RyZWFtIGlzIHRvbyBtYWluc3RyZWFtCiNpbmNsdWRlIDxjc3RkaW8+Ci8vIGJpdGNoIHBsZWFzZQojaW5jbHVkZSA8aW9zdHJlYW0+CiNpbmNsdWRlIDxhbGdvcml0aG0+CiNpbmNsdWRlIDxjc3RkbGliPgojaW5jbHVk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