#include <algorithm>
#include <iostream>
#include <cstring>
#include <cstdio>
#define mid (l+r>>1)
#define lc (o<<1)
#define rc (o<<1|1)
using namespace std;
const int maxn = 1000010;

int sumv[maxn*4], ql, qr, v, _sum;
int n;

void insert(int o, int l, int r)
{
    if(ql <= l && r <= qr) {
        sumv[o] = 1<<v;
        return;
    }
    sumv[lc] = sumv[rc] = sumv[o];
    sumv[o] = 0;
    int m = mid;
    if(ql <= m) insert(lc, l, m);
    if(qr >  m) insert(rc, m+1, r);
    sumv[o] = sumv[lc] | sumv[rc];
    printf("%d %d %d\n", l, r, sumv[o]);
}

void query(int o, int l, int r)
{
    if(ql <= l && r <= qr) {
        _sum |= sumv[o];
        return;
    }
    int m = mid;
    if(ql <= m) query(lc, l, m);
    if(qr >  m) query(rc, m+1, r);
}

int gao(int s)
{
    int ans = 0;
    while(s) {
        ans += s&1;
        s >>= 1;
    }
    return ans;
}

int main()
{
    freopen("b.txt", "r", stdin);
    freopen("bout", "w", stdout);
    int m;
    while(scanf("%d%d", &n, &m), n)
    {
        printf("%d %d\n", n, m);
        if(n == 0) break;
        memset(sumv, 0, sizeof sumv);
        char op[3];
        for(int i = 0; i < m; i++)
        {
            scanf("%s", op);
            if(op[0] == 'P') {
                scanf("%d%d%d", &ql, &qr, &v); v--;
                insert(1, 1, n);
                puts("");
            } else {
                scanf("%d%d", &ql, &qr);
                _sum = 0;
                query(1, 1, n);
                printf("__%d\n", gao(_sum));
            }
        }
    }
    return 0;
}
/*
5 10
1 3 4
1 5 4

1 2 12
1 3 12
1 5 12

__1
__2
1 3 12
1 5 12

1 3 76
1 5 76

__3
__2
4 5 204
1 5 204

__4
*/