import java.io.*;
import java.util.*;
import static java.lang.Math.*;

public class gonarch_nlog2n_vd {

	int max = (int) (1e+5);

	long[] tree = new long[4 * max + 1];
	long sumd = 0;

	void update(int l, int r, long wht, int l1, int r1, int i) {
		if (r1 < l1) {
			return;
		}
		if ((l == l1) && (r == r1)) {
			tree[i] += wht;
			return;
		}
		int x = (l + r) / 2;
		if (r1 <= x) {
			update(l, x, wht, l1, r1, i * 2);
		} else if (l1 > x) {
			update(x + 1, r, wht, l1, r1, i * 2 + 1);
		} else {
			update(l, x, wht, l1, x, i * 2);
			update(x + 1, r, wht, x + 1, r1, i * 2 + 1);
		}
	}

	void update(int k, long cnt) {
		sumd += cnt;
		for (int mul = 0; mul * k <= max; mul++) {
			update(1, max, mul * cnt * k, Math.max(mul * k,1),
					Math.min(mul * k + k - 1, max), 1);
		}
	}

	void count() throws IOException {
		int m = nextInt();
		for (int i = 0; i < m; i++) {
			int g = nextInt();
			long c = nextInt();
			update(g, c);
		}
		int n = nextInt();
		for (int i = 0; i < n; i++) {
			char c = nextToken().charAt(0);
			if (c == '+') {
				update(nextInt(), 1);
			} else if (c == '-') {
				update(nextInt(), -1);
			} else {
				int val = nextInt();
				out.println(val * sumd - get(1, max, 1, val));
			}
		}
	}

	private long get(int l, int r, int i, int x) {
		if (l == r) {
			return tree[i];
		}
		if (x <= (l + r) / 2) {
			return tree[i] + get(l, (l + r) / 2, i * 2, x);
		} else {
			return tree[i] + get((l + r) / 2 + 1, r, i * 2 + 1, x);
		}
	}

	BufferedReader in;
	PrintWriter out;
	StringTokenizer str;
	String readline;

	String nextToken() throws IOException {
		while (str == null || !str.hasMoreTokens()) {
			readline = in.readLine();
			if (readline == null) {
				return null;
			} else {
				str = new StringTokenizer(readline);
			}
		}
		return str.nextToken();
	}

	int nextInt() throws IOException {
		return Integer.parseInt(nextToken());
	}

	long nextLong() throws IOException {
		return Long.parseLong(nextToken());
	}

	double nextDouble() throws IOException {
		return Double.parseDouble(nextToken());
	}

	void run() throws IOException {
		in = new BufferedReader(new FileReader("gonarch.in"));
		out = new PrintWriter("gonarch.out");
		count();
		out.close();
	}

	public static void main(String[] args) throws IOException {
		new gonarch_nlog2n_vd().run();
	}
}