/*
Sprendimo autorius - Vytis Banaitis
*/

#include <cstdio>
#include <cstdlib>

using namespace std;

struct node { node *left, *right; int s, h; };

node root;
int n;
int d;

void destroy(node *d)
{
    if (d->left) destroy(d->left);
    if (d->right) destroy(d->right);
    delete d;
}

inline int max(const int& a, const int& b) { return a < b ? b : a; }
inline int min(const int& a, const int& b) { return a > b ? b : a; }

void _update(node *n, int k, int t, int a, int b, int D)
{
    if (a > b) return;
    int left = t<<k;
    int right = (t+1)<<k;
    if (left == a && right == b + 1) {
        if (n->left) { destroy(n->left); n->left = 0; }
        if (n->right) { destroy(n->right); n->right = 0; }
        n->s = D * 1<<k;
        n->h = max(0,n->s);
    }
    else {
        if (!n->left) {
            n->left = new node;
            n->left->left = n->left->right = 0;
            n->right = new node;
            n->right->left = n->right->right = 0;
            n->left->s = n->left->h = n->right->s = n->right->h = n->s/2;
        }
        _update(n->left, k-1, t*2, min(a,(left+right)/2), min(b,(left+right)/2-1), D);
        _update(n->right, k-1, t*2+1, max(a,(left+right)/2), max(b,(left+right)/2-1), D);
        n->s = n->left->s + n->right->s;
        n->h = max(n->left->h, n->left->s + n->right->h);
    }
}

inline void update(int a, int b, int D)
{
    _update(&root, d, 0, a, b, D);
}

int _check(node *n, int k, int h)
{
    if (n->left) {
        if (h < n->left->h) return _check(n->left, k-1, h);
        else return (1<<(k-1)) + _check(n->right, k-1, h - n->left->s);
    }

    if (h < n->h) return h/(n->s/(1<<k));
    return 1<<k;
}

inline int check(int h)
{
    return _check(&root, d, h);
}

int main()
{
    freopen("mou.in","r",stdin);
    freopen("mou.out","w",stdout);
    scanf("%d",&n);
    while (1<<(++d) < n);
    char c;
    int a, b, D;
    scanf(" %c",&c);
    while (c != 'E') {
        if (c == 'I') {
            scanf("%d%d%d",&a,&b,&D);
            update(a-1, b-1, D);
        }
        else {
            scanf("%d",&a);
            printf("%d\n",min(check(a),n));
        }
        scanf(" %c",&c);
    }
    return 0;
}
