import java.io.BufferedReader;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.StringTokenizer;

public class gonarch_akov {
	FastScanner in;
	PrintWriter out;

	final int maxN = 100 * 1000;
	final int lengthOfBlock = (int) Math.sqrt(maxN + 1) + 1;
	final int countBlocks = ((maxN + 1) + lengthOfBlock - 1) / lengthOfBlock;

	long[] sumBlocks = new long[countBlocks];
	long[] sumInBlock = new long[maxN + 1];
	long[] a = new long[maxN + 1];

	void add(int i, long value) {
		value *= i;
		a[i] += value;
		int numOfBlock = i / lengthOfBlock;
		int startPosition = numOfBlock * lengthOfBlock;
		int endPosition = Math.min(startPosition + lengthOfBlock, maxN + 1);
		for (int j = i; j < endPosition; j++) {
			sumInBlock[j] += value;
		}
		for (int j = numOfBlock; j < countBlocks; j++) {
			sumBlocks[j] += value;
		}
	}

	long sum(int r) {
		int numOfBlock = r / lengthOfBlock;
		long result = sumInBlock[r];
		if (numOfBlock != 0)
			result += sumBlocks[numOfBlock - 1];
		return result;
	}

	public void solve() throws IOException {
		long countCrabes = 0;
		int m = in.nextInt();
		for (int i = 0; i < m; i++) {
			int g = in.nextInt(), c = in.nextInt();
			add(g, c);
			countCrabes += c;
		}

		int countQueries = in.nextInt();
		for (int i = 0; i < countQueries; i++) {
			char type = in.next().charAt(0);
			if (type == '+') {
				int k = in.nextInt();
				add(k, 1);
				countCrabes++;
			} else if (type == '-') {
				int k = in.nextInt();
				add(k, -1);
				countCrabes--;
			} else {
				int n = in.nextInt();
				long answer = 1L * n * countCrabes;
				int sqrtN = (int) Math.sqrt(n);
				for (int k = 1; k <= sqrtN; k++) {
					long count = a[k] / k;
					answer += count * ((n % k) - n);
				}
				for (int ndivk = 1; ndivk <= sqrtN; ndivk++) {
					int kmin = Math.max(n / (ndivk + 1) + 1, sqrtN + 1);
					int kmax = n / ndivk;
					if (kmin > kmax)
						continue;
					answer -= (sum(kmax) - sum(kmin - 1)) * ndivk;
				}
				out.println(answer);
			}
		}
	}

	public void run() {
		try {
			in = new FastScanner(new File("gonarch.in"));
			out = new PrintWriter(new File("gonarch.out"));

			long time = System.currentTimeMillis();
			solve();
			System.err.println(System.currentTimeMillis() - time);

			out.close();
		} catch (IOException e) {
			e.printStackTrace();
		}
	}

	class FastScanner {
		BufferedReader br;
		StringTokenizer st;

		FastScanner(File f) {
			try {
				br = new BufferedReader(new FileReader(f));
			} catch (FileNotFoundException e) {
				e.printStackTrace();
			}
		}

		String next() {
			while (st == null || !st.hasMoreTokens()) {
				try {
					st = new StringTokenizer(br.readLine());
				} catch (IOException e) {
					e.printStackTrace();
				}
			}
			return st.nextToken();
		}

		int nextInt() {
			return Integer.parseInt(next());
		}

		long nextLong() {
			return Long.parseLong(next());
		}

		double nextDouble() {
			return Double.parseDouble(next());
		}

	}

	public static void main(String[] arg) {
		new gonarch_akov().run();
	}
}