#include <bits/stdtr1c++.h>

using namespace std;

//easy O(n*sqrt(n)) through square root decomposition
//long but repetitive code w/ easy logic
int C, N, O;
const int blk_size = 2500; //roughly sqrt(4587520)
struct block {
	int arr[blk_size], del, min_val, max_val, done_update;
	block() {
		memset(arr, 0, sizeof arr);
		del = min_val = max_val = 0;
		done_update = 1;
	}
	
	void lazy_update() {
		if (done_update) return;
		min_val = 10000, max_val = -10000;
		for (int i = 0; i < blk_size; i++) {
			arr[i] += del;
			min_val = std::min(min_val, arr[i]);
			max_val = std::max(max_val, arr[i]);
		}
		del = 0;
		done_update = 1;
	}
	
	int min(int a, int b) {
		lazy_update();
		int s = 10000;
		for (int i = a; i < b; i++) {
			s = std::min(s, arr[i]);
		}
		return s;
	}
	int min() {
		return min_val;
	}
	
	int max(int a, int b) {
		lazy_update();
		int s = -10000;
		for (int i = a; i < b; i++) {
			s = std::max(s, arr[i]);
		}
		return s;
	}
	int max() {
		return max_val;
	}
	
	void add_range(int a, int b, int v) {
		for (int i = a; i < b; i++) {
			arr[i] += v;
		}
		done_update = 0;
		lazy_update();
	}
	void add_range(int v) {
		done_update = 0;
		del += v;
		min_val += v;
		max_val += v;
	}
	int query(int id) {
		lazy_update();
		return arr[id];
	}
};

block blks[blk_size+1];
int query(int id) {
	int blk_id = id/blk_size;
	int i = id%blk_size;
	return blks[blk_id].query(i);
}

int add_range(int a, int b, int v) {
	int start_blk = a/blk_size, st_i = a%blk_size;
	int end_blk = b/blk_size, en_i = b%blk_size+1;

	if (start_blk == end_blk) {
		if (v > 0) {
			int M = blks[start_blk].max(st_i, en_i);
			v = min(v, N-M);
		} else {
			int m = blks[start_blk].min(st_i, en_i);
			v = max(v, -m);
		}
		blks[start_blk].add_range(st_i, en_i, v);
		return v;
	} else {
		if (v > 0) {
			int M0 = blks[start_blk].max(st_i, blk_size);
			int M1 = blks[end_blk].max(0, en_i);
			int M2 = -10000;
			for (int i = start_blk+1; i < end_blk; i++) {
				M2 = max(M2, blks[i].max());
			}
			int M = max(M0, max(M1, M2));
			v = min(v, N-M);
		} else {
			int m0 = blks[start_blk].min(st_i, blk_size);
			int m1 = blks[end_blk].min(0, en_i);
			int m2 = 10000;
			for (int i = start_blk+1; i < end_blk; i++) {
				m2 = min(m2, blks[i].min());
			}
			int m = min(m0, min(m1, m2));
			v = max(v, -m);
		}
		
		blks[start_blk].add_range(st_i, blk_size, v);
		blks[end_blk].add_range(0, en_i, v);
		for (int i = start_blk+1; i < end_blk; i++) {
			blks[i].add_range(v);
		}
		return v;
	}
}

int main() {
	ios_base::sync_with_stdio(0);
	cin >> C >> N >> O;
	for (int i = 0; i < O; i++) {
		string s; cin >> s;
		if (s == "state") {
			int id; cin >> id;
			cout << query(id) << '\n';
		} else if (s == "groupchange") {
			int a, b, v; cin >> a >> b >> v;
			cout << add_range(a,b,v) << '\n';
		} else {
			int a, v; cin >> a >> v;
			cout << add_range(a, a, v) << '\n';
		}
	}
	
	return 0;
}