import java.util.*;
import java.util.Map.Entry;
import java.io.*;

public class gonarch_akov_N2 {
	FastScanner in;
	PrintWriter out;

	public void solve() throws IOException {
		HashMap<Integer, Integer> count = new HashMap<Integer, Integer>();
		int m = in.nextInt();
		for (int i = 0; i < m; i++) {
			int g = in.nextInt(), c = in.nextInt();
			count.put(g, c);
		}
		int countQueries = in.nextInt();
		for (int i = 0; i < countQueries; i++) {
			char type = in.next().charAt(0);
			if (type == '+') {
				int k = in.nextInt();
				Integer old = count.get(k);
				if (old == null) old = 0;
				count.put(k, old + 1);
			} else if (type == '-') {
				int k = in.nextInt();
				Integer old = count.get(k);
				if (old == null) old = 0;
				count.put(k, old - 1);
			} else {
				long answer = 0;
				int n = in.nextInt();
				for (Entry<Integer, Integer> e : count.entrySet()) {
					answer += (n % e.getKey()) * 1L * e.getValue();
				}
				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_N2().run();
	}
}