#include <bits/stdc++.h>
using namespace std;
int main() {
  int N;
  cin >> N;
  vector<long long> as(N);
  long long b;
  long long c;
  int Q;
  for (int i = 0; i < N; i++) {
    cin >> as.at(i);
  }
  cin >> Q;
  for (int i = 0; i < Q; i++) {
    cin >> b >> c;
    for (int j = 0; j < N; j++) {
      if (as[j] == b) {
        as[j] = c;
      }
    }
    long long sum = 0;
    for (int j = 0; j < (int)as.size(); j++) {
      sum += as[j];
    }
    cout << sum << endl;
  }
  return 0;
}
