// Hint: Don't look, No need, Let'em Play.
#pragma GCC optimize("O2")
#include <bits/stdc++.h>
#include "bits/stdc++.h"
using namespace std;
#define fast ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#ifndef bhupixb
#define var(...)
#define stl(...)
#endif
#define single_test
using pi = pair<int,int>;
vector<vector<pair<int,int>>> v;
int n, q;
const int N = 1e5 + 3;
const int mx = 320; // size of block
vector<int> a, block;
void upd(int pos, int val) {
a[pos] = val;
int found = -1;
int cur_block = block[pos];
const int x = v[cur_block].size();
for (int i = 0; i < x; ++i) {
if (v[cur_block][i].second == pos) {
if (v[cur_block][i].first == val) {
return;
}
found = i;
break;
}
}
assert(found != -1);
if (val > v[cur_block][found].first) {
v[cur_block][found].first = val;
while (found + 1 < x && val > v[cur_block][found + 1].first) {
swap(v[cur_block][found], v[cur_block][found + 1]);
++found;
}
}
else {
v[cur_block][found].first = val;
while (found > 0 && val < v[cur_block][found - 1].first) {
swap(v[cur_block][found], v[cur_block][found - 1]);
--found;
}
}
}
int query(int l, int r, int k) {
int ans = 0;
for (int i = l; i <= r; ++i) {
ans += a[i] <= k;
}
return ans;
}
int query_bs(int l, int r, int k) {
int ans = 0;
for (int i = l; i <= r; ++i) {
assert(!v[i].empty());
int lo = 0, hi = (int)v[i].size() - 1, mid, c = 0;
while (lo <= hi) {
mid = (lo + hi) >> 1;
if (v[i][mid].first <= k) {
lo = mid + 1;
c = mid + 1;
}
else {
hi = mid - 1;
}
}
ans += c;
}
return ans;
}
void solve() {
cin >> n >> q;
a.resize(n + 1);
block.resize(n + 1);
for (int i = 1; i <= n; ++i) {
cin >> a[i];
}
int cur = 0, sz = 0;
for (int i = 1; i <= n; ++i) {
block[i] = cur;
++sz;
if (sz == mx) sz = 0, ++cur;
}
v.resize(block[n] + 1);
for (int i = 1; i <= n; ) {
cur = i;
sz = 0;
while (i <= n && block[i] == block[cur]) {
++i;
++sz;
}
int cur_block = block[cur];
v[cur_block].resize(sz);
var(sz, cur_block);
int idx = 0;
while (sz--) {
v[cur_block][idx] = {a[cur], cur};
++idx;
cur += 1;
}
sort(v[cur_block].begin(), v[cur_block].end());
}
for (int i = 0; i < (int)v.size(); ++i) {
stl(v[i]);
}
stl(a);
int l, r, k, pos, val;
while (q--) {
char type;
cin >> type;
if (type == 'C') {
cin >> l >> r >> k;
if (block[l] == block[r]) {
cout << query(l, r, k) << '\n';
}
else {
int ans = query_bs(block[l] + 1, block[r] - 1, k);
int x = l;
while (x <= n && block[x] == block[l]) {
ans += a[x] <= k;
++x;
}
x = r;
while (x > 0 && block[x] == block[r]) {
ans += a[x] <= k;
--x;
}
cout << ans << '\n';
}
}
else {
cin >> pos >> val;
upd(pos, val);
}
}
}
signed main() {
fast;
int t = 1;
#ifndef single_test
cin >> t;
#endif
while (t--) {
solve();
}
return 0;
}
Ly8gSGludDogRG9uJ3QgbG9vaywgTm8gbmVlZCwgTGV0J2VtIFBsYXkuCiNwcmFnbWEgR0NDIG9wdGltaXplKCJPMiIpCiNpbmNsdWRlIDxiaXRzL3N0ZGMrKy5oPgojaW5jbHVkZSAiYml0cy9zdGRjKysuaCIKIAp1c2luZyBuYW1lc3BhY2Ugc3RkOwogCiNkZWZpbmUgZmFzdCBpb3NfYmFzZTo6c3luY193aXRoX3N0ZGlvKDApO2Npbi50aWUoMCk7Y291dC50aWUoMCk7CiAKI2lmbmRlZiBiaHVwaXhiCiAgICAjZGVmaW5lIHZhciguLi4pCiAgICAjZGVmaW5lIHN0bCguLi4pCiNlbmRpZgogCiNkZWZpbmUgc2luZ2xlX3Rlc3QKIAp1c2luZyBwaSA9IHBhaXI8aW50LGludD47CnZlY3Rvcjx2ZWN0b3I8cGFpcjxpbnQsaW50Pj4+IHY7CiAKaW50IG4sIHE7CmNvbnN0IGludCBOID0gMWU1ICsgMzsKY29uc3QgaW50IG14ID0gMzIwOyAvLyBzaXplIG9mIGJsb2NrCnZlY3RvcjxpbnQ+IGEsIGJsb2NrOwoKdm9pZCB1cGQoaW50IHBvcywgaW50IHZ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ppbnQgcXVlcnkoaW50IGwsIGludCByLCBpbnQgaykgewogICAgaW50IGFucyA9IDA7CiAgICBmb3IgKGludCBpID0gbDsgaSA8PSByOyArK2kpIHsKICAgICAgICBhbnMgKz0gYVtpXSA8PSBrOwogICAgfQogICAgcmV0dXJuIGFuczsKfQogCmludCBxdWVyeV9icyhpbnQgbCwgaW50IHIsIGludCBrKSB7CiAgICBpbnQgYW5zID0gMDsKICAgIGZvciAoaW50IGkgPSBsOyBpIDw9IHI7ICsraSkgewogICAgICAgIGFzc2VydCghdltpXS5lbXB0eSgpKTsKICAgICAgICBpbnQgbG8gPSAwLCBoaSA9IChpbnQpdltpXS5zaXplKCkgLSAxLCBtaWQsIGMgPSAwOwogICAgICAgIHdoaWxlIChsbyA8PSBoaSkgewogICAgICAgICAgICBtaWQgPSAobG8gKyBoaSkgPj4gMTsKICAgICAgICAgICAgaWYgKHZbaV1bbWlkXS5maXJzdCA8PSBrKSB7CiAgICAgICAgICAgICAgICBsbyA9IG1pZCArIDE7CiAgICAgICAgICAgICAgICBjID0gbWlkICsgMTsKICAgICAgICAgICAgfQogICAgICAgICAgICBlbHNlIHsKICAgICAgICAgICAgICAgIGhpID0gbWlkIC0gMTsKICAgICAgICAgICAgfQogICAgICAgIH0KICAgICAgICBhbnMgKz0gYzsKICAgIH0KICAgIHJldHVybiBhbnM7Cn0KIAp2b2lkIHNvbHZlKCkgewogICAgY2luID4+IG4gPj4gcTsKICAgIGEucmVzaXplKG4gKyAxKTsKICAgIGJsb2NrLnJlc2l6ZShuICsgMSk7CiAgICBmb3IgKGludCBpID0gMTsgaSA8PSBuOyArK2kpIHsKICAgICAgICBjaW4gPj4gYVtpXTsKICAgIH0KICAgIGludCBjdXIgPSAwLCBzeiA9IDA7CiAgICBmb3IgKGludCBpID0gMTsgaSA8PSBuOyArK2kpIHsKICAgICAgICBibG9ja1tpXSA9IGN1cjsKICAgICAgICArK3N6OwogICAgICAgIGlmIChzeiA9PSBteCkgc3ogPSAwLCArK2N1cjsKICAgIH0KICAgIHYucmVzaXplKGJsb2NrW25dICsgMSk7CiAgICBmb3IgKGludCBpID0gMTsgaSA8PSBuOyApIHsKICAgICAgICBjdXIgPSBpOwogICAgICAgIHN6ID0gMDsKICAgICAgICB3aGlsZSAoaSA8PSBuICYmIGJsb2NrW2ldID09IGJsb2NrW2N1cl0pIHsKICAgICAgICAgICAgKytpOwogICAgICAgICAgICArK3N6OwogICAgICAgIH0KICAgICAgICBpbnQgY3VyX2Jsb2NrID0gYmxvY2tbY3VyXTsKICAgICAgICB2W2N1cl9ibG9ja10ucmVzaXplKHN6KTsKICAgICAgICB2YXIoc3osIGN1cl9ibG9jayk7CiAgICAgICAgaW50IGlkeCA9IDA7CiAgICAgICAgd2hpbGUgKHN6LS0pIHsKICAgICAgICAgICAgdltjdXJfYmxvY2tdW2lkeF0gPSB7YVtjdXJdLCBjdXJ9OwogICAgICAgICAgICArK2lkeDsKICAgICAgICAgICAgY3VyICs9IDE7CiAgICAgICAgfQogICAgICAgIHNvcnQodltjdXJfYmxvY2tdLmJlZ2luKCksIHZbY3VyX2Jsb2NrXS5lbmQoKSk7CiAgICB9CiAgICBmb3IgKGludCBpID0gMDsgaSA8IChpbnQpdi5zaXplKCk7ICsraSkgewogICAgICAgIHN0bCh2W2ldKTsKICAgIH0KICAgIHN0bChhKTsKICAgIGludCBsLCByLCBrLCBwb3MsIHZhbDsKICAgIHdoaWxlIChxLS0pIHsKICAgICAgICBjaGFyIHR5cGU7CiAgICAgICAgY2luID4+IHR5cGU7CiAgICAgICAgaWYgKHR5cGUgPT0gJ0MnKSB7CiAgICAgICAgICAgIGNpbiA+PiBsID4+IHIgPj4gazsKICAgICAgICAgICAgaWYgKGJsb2NrW2xdID09IGJsb2NrW3JdKSB7CiAgICAgICAgICAgICAgICBjb3V0IDw8IHF1ZXJ5KGwsIHIsIGspIDw8ICdcbic7CiAgICAgICAgICAgIH0KICAgICAgICAgICAgZWxzZSB7CiAgICAgICAgICAgICAgICBpbnQgYW5zID0gcXVlcnlfYnMoYmxvY2tbbF0gKyAxLCBibG9ja1tyXSAtIDEsIGspOwogICAgICAgICAgICAgICAgaW50IHggPSBsOwogICAgICAgICAgICAgICAgd2hpbGUgKHggPD0gbiAmJiBibG9ja1t4XSA9PSBibG9ja1tsXSkgewogICAgICAgICAgICAgICAgICAgIGFucyArPSBhW3hdIDw9IGs7CiAgICAgICAgICAgICAgICAgICAgKyt4OwogICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgeCA9IHI7CiAgICAgICAgICAgICAgICB3aGlsZSAoeCA+IDAgJiYgYmxvY2tbeF0gPT0gYmxvY2tbcl0pIHsKICAgICAgICAgICAgICAgICAgICBhbnMgKz0gYVt4XSA8PSBrOwogICAgICAgICAgICAgICAgICAgIC0teDsKICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgIGNvdXQgPDwgYW5zIDw8ICdcbic7CiAgICAgICAgICAgIH0KICAgICAgICB9CiAgICAgICAgZWxzZSB7CiAgICAgICAgICAgIGNpbiA+PiBwb3MgPj4gdmFsOwogICAgICAgICAgICB1cGQocG9zLCB2YWwpOwogICAgICAgIH0KICAgIH0KfQogCnNpZ25lZCBtYWluKCkgewogICAgZmFzdDsKICAgIGludCB0ID0gMTsKICAgICNpZm5kZWYgc2luZ2xlX3Rlc3QKICAgICAgICBjaW4gPj4gdDsKICAgICNlbmRpZgogICAgd2hpbGUgKHQtLSkgewogICAgICAgIHNvbHZlKCk7CiAgICB9CiAKICAgIHJldHVybiAwOwp9IA==