#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, q;
  cin >> n;
  int x[n];
  for (int i = 0; i < n; i++) {
    cin >> x[i];
  }
  cin >> q;
  int z[q], y[q];
  int t[q];
  for (int i = 0; i < q; i++) {
    cin >> z[i] >> y[i];
  }
  for (int j = 0; j < q; j++) {
    t[j] = 0;
    for (int i = 0; i < n; i++) {
      if (x[i] == z[j]) {
        x[i] = y[j];
        t[j] += x[i];
      } else
        t[j] += x[i];
    }
    cout << t[j] << endl;
  }
  return 0;
}
