#include <bits/stdc++.h>
using namespace std;
int main() {
  int n1, n2, a[100000];
  scanf("%d", &n1);
  int i = 0;
  for (; i < n1; ++i) {
    scanf("%d", &a[i]);
  }
  scanf("%d", &n2);
  for (int j = 0; j < n2; ++j) {
    int x, y, sum = 0;
    scanf("%d%d", &x, &y);
    for (int i = 0; i < n1; ++i)
      if (a[i] == x) {
        sum += y;
        a[i] = y;
      } else
        sum += a[i];
    cout << sum;
  }
  return 0;
}
