#include <bits/stdc++.h>
using ll = long long;
using namespace std;
const ll md = 1e9 + 7;
ll sumAll(vector<int> A) {
  ll res = 0;
  for (int i = 0; i < (int)A.size(); i++) {
    res += A[i];
  }
  return res;
}
int main() {
  int N;
  cin >> N;
  vector<int> A;
  for (int i = 0; i < N; i++) {
    int a;
    cin >> a;
    A.push_back(a);
  }
  int Q;
  cin >> Q;
  vector<int> B, C;
  for (int i = 0; i < Q; i++) {
    int b, c;
    cin >> b >> c;
    B.push_back(b);
    C.push_back(c);
  }
  for (int i = 0; i < Q; i++) {
    for (int j = 0; j < N; j++) {
      if (A[j] == B[i]) A[j] = C[i];
    }
    cout << sumAll(A) << endl;
  }
  return 0;
}
