int main(){
  //Treap::Node* test = Treap::nil;
  //Treap::insert(test, 1);
  //cout << Treap::getRank(test, 2) << endl;
  scanf("%d", &TestNum);
  while (TestNum--){
    scanf("%d", &n);
    int m; scanf("%d", &m);
    for (int i = 0; i < n; i++) scanf("%d", &a[i]);
    SegmentTree::Node root(0, n - 1); 
    tree.init(root);
    while (m--){
      char buf[32]; scanf("%s", buf);
      if (buf[0] == 'Q'){
        int i, j, k; scanf("%d %d %d", &i, &j, &k);
        printf("%d\n", getKth(i - 1, j - 1, k - 1));
      }else{
        int i, t; scanf("%d %d", &i, &t);
        tree.gao(i -1 , i - 1).update(root, a[i - 1], t);
        a[i - 1] = t;
      }
      //printf("new_cnt: %d\n", new_cnt);
    }
    tree.clear(root);
    //printf("new_cnt: %d\n", new_cnt);
    assert(new_cnt == 0);
    //len = 1;
  }
}
int getKth(int from, int to, int k){
  SegmentTree::Node root(0, n - 1); 
  int lo = 0, hi = 1000*1024*1024; 
  while (lo < hi){
    int m = (lo + hi + 1) / 2;
    int less_than_m = tree.gao(from, to).getRank(root, m);
    //printf("%d: %d %d, %d\n", m, lo, hi, less_than_m); 
    if (less_than_m > k) hi = m - 1;
    else lo = m;
  }
  return lo;
};