#include <bits/stdc++.h>
using namespace std;
int main() {
  long x, Q;
  cin >> x;
  long y[x];
  for (long i = 0; i < x; i++) {
    cin >> y[i];
  }
  cin >> Q;
  for (int i = 0; i < Q; i++) {
    long a, b, sum = 0;
    cin >> a >> b;
    for (int j = 0; j < x; j++) {
      if (a == y[j]) {
        y[j] = b;
      }
      sum += y[j];
    }
    cout << sum << endl;
  }
}
