#include <bits/stdc++.h>
using namespace std;
long long S(long long x) {
  long long ans = sqrt(x);
  if (ans * ans == x) return true;
  return false;
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  int t;
  t = 1;
  while (t--) {
    int n, q, sum = 0, l, r, input;
    std::vector<int> v;
    cin >> n;
    for (int i = 0; i <= n - 1; i++) {
      cin >> input;
      v.push_back(input);
    }
    cin >> q;
    for (int i = 0; i <= q - 1; i++) {
      cin >> l >> r;
      for (int i = 0; i <= n - 1; i++) {
        if (v[i] == l) {
          sum += r;
          v[i] = r;
        } else
          sum += v[i];
      }
      printf("%d\n", sum);
      sum = 0;
    }
  }
  cerr << "Time taken : " << (float)clock() / CLOCKS_PER_SEC << " secs" << endl;
  return 0;
}
