#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> pll;
const int N = 1e5 + 5, M = 1e4 + 5, mod = 7;
ll n, q, t;
struct Node
{
ll l, r, col;
bool vis[32];
};
Node tr[N * 4];
#define lc p << 1
#define rc p << 1 | 1
void build(ll p, ll x, ll y)
{
tr[p].l = x;
tr[p].r = y;
tr[p].vis[1] = 1;
if (x == y)
return;
ll m = tr[p].l + tr[p].r >> 1;
build(lc, x, m);
build(rc, m + 1, y);
}
void pushup(ll p)
{
for (ll i = 1; i <= t; i++)
tr[p].vis[i] = tr[lc].vis[i] || tr[rc].vis[i];
}
void pushdown(ll p)
{
if (tr[p].col)
{
memset(tr[lc].vis, 0, sizeof(tr[lc].vis));
memset(tr[rc].vis, 0, sizeof(tr[rc].vis));
tr[lc].vis[tr[p].col] = 1;
tr[rc].vis[tr[p].col] = 1;
tr[lc].col = tr[p].col;
tr[rc].col = tr[p].col;
tr[p].col = 0;
}
}
void change(ll p, ll x, ll y, ll k)
{
if (x <= tr[p].l && tr[p].r <= y)
{
memset(tr[p].vis, 0, sizeof(tr[p].vis));
tr[p].vis[k] = 1;
tr[p].col = k;
return;
}
pushdown(p);
ll m = tr[p].l + tr[p].r >> 1;
if (x <= m)
change(lc, x, y, k);
if (m + 1 <= y)
change(rc, x, y, k);
pushup(p);
}
ll query(ll p, ll x, ll y)
{
ll cnt = 0, m = tr[p].l + tr[p].r >> 1;
if (x <= tr[p].l && tr[p].r <= y)
{
for (ll i = 1; i <= 30; i++)
if (tr[p].vis[i])
cnt++;
return cnt;
}
pushdown(p);
if (x <= m)
cnt += query(lc, x, y);
if (m + 1 <= y)
cnt += query(rc, x, y);
return cnt;
}
int main()
{
cin >> n >> t >> q;
build(1, 1, n);
char op;
ll x, y, k;
while (q--)
{
cin >> op;
if (op == 'C')
{
cin >> x >> y >> k;
change(1, min(x, y), max(x, y), k);
}
else
{
cin >> x >> y;
cout << query(1, min(x, y), max(x, y)) << endl;
}
}
return 0;
}