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