#include <bits/stdc++.h>
using namespace std;
void fastscan(int &x) {
  bool neg = false;
  register int c;
  x = 0;
  c = getchar();
  if (c == '-') {
    neg = true;
    c = getchar();
  }
  for (; (c > 47 && c < 58); c = getchar()) x = (x << 1) + (x << 3) + c - 48;
  if (neg) x *= -1;
}
int main() {
  int n, q, sum = 0, b, k;
  fastscan(n);
  int a[n];
  for (int i = 0; i < n; i++) fastscan(a[i]);
  fastscan(k);
  for (int i = 0; i < k; i++) {
    sum = 0;
    fastscan(b);
    fastscan(q);
    for (int j = 0; j < n; j++) {
      if (b == a[j]) a[j] = q;
      sum = sum + a[j];
    }
    cout << sum << "\n";
  }
  return 0;
}
