import java.io.*; import java.util.*; public class Main { BufferedReader br; PrintWriter out; StringTokenizer st; public String nextToken() throws IOException { while ((st == null) || (!st.hasMoreTokens())) st = new StringTokenizer(br.readLine()); return st.nextToken(); } public int nextInt() throws IOException { return Integer.parseInt(nextToken()); } public double nextDouble() throws IOException { return Double.parseDouble(nextToken()); } public long nextLong() throws IOException { return Long.parseLong(nextToken()); } void add(int k, long x, int group, long[] fenv, long[] fenv2) { for (int i = group; i < fenv.length; i += group) { if (i >= k) fenv[i] += x; } for (int i = k; i == 0 || i % group != 0; i++) { fenv2[i] += x; } } long get(int t, int group, long[] fenv, long[] fenv2) { if (t < 0) return 0; return fenv2[t] + fenv[t / group * group]; } long get(int l, int r, int group, long[] fenv, long[] fenv2) { return get(r, group, fenv, fenv2) - get(l - 1, group, fenv, fenv2); } void myAs(boolean fl) { if (!fl) throw new AssertionError(); } public void solve() throws IOException { int maxN = 100005; int group = 250; long[] c = new long[maxN]; long[] c2 = new long[maxN]; long[] s = new long[maxN]; long[] s2 = new long[maxN]; int[] count = new int[maxN]; int n = nextInt(); myAs((0 <= n) && (n <= 100000)); HashSet<Integer> was= new HashSet<Integer>(); for (int i = 0; i < n; i++) { int a = nextInt(); myAs((1 <= a) && (a <= 100000)); myAs(!was.contains(a)); was.add(a); long b = nextInt(); myAs((1 <= b) && (b <= 100000)); add(a, b, group, c, c2); add(a, b * a, group, s, s2); count[a] += b; } int t = nextInt(); myAs((1 <= t) && (t <= 100000)); for (int i = 0; i < t; i++) { String q = nextToken(); myAs(q.equals("+") || q.equals("-") || q.equals("?")); if (q.equals("+")) { int a = nextInt(); myAs((1 <= a) && (a <= 100000)); add(a, 1, group, c, c2); add(a, a, group, s, s2); count[a]++; } if (q.equals("-")) { int a = nextInt(); myAs((1 <= a) && (a <= 100000)); add(a, -1, group, c, c2); add(a, -a, group, s, s2); count[a]--; myAs(count[a] >= 0); } if (q.equals("?")) { int a = nextInt(); myAs((1 <= a) && (a <= 100000)); long sum = 0; int last = 0; for (int div = 0; div * div <= a; div++) { int l = a / (div + 1) + 1; int r = maxN - 1; if (l > r) continue; if (div != 0) { r = a / div; } sum = sum + get(l, r, group, c, c2) * a - get(l, r, group, s, s2) * div; last = div; } for (int x = 1; a / x > last; x++) { sum = sum + count[x] * (a % x); } out.println(sum); } } } public void run() { try { br = new BufferedReader(new InputStreamReader(System.in)); out = new PrintWriter(System.out); solve(); out.close(); } catch (IOException e) { e.printStackTrace(); } } public static void main(String[] args) { new Main().run(); } }