#include <bits/stdc++.h>
using namespace std;
int main() {
  int N, Q, B, C;
  vector<int> A;
  vector<pair<int, int>> BC;
  vector<int> res;
  cin >> N;
  A.resize(N);
  for (int i = 0; i < N; i++) {
    cin >> A.at(i);
  }
  cin >> Q;
  for (int i = 0; i < Q; i++) {
    cin >> B >> C;
    pair<int, int> bc = make_pair(B, C);
    BC.emplace_back(bc);
  }
  for (int i = 0; i < Q; i++) {
    for (int j = 0; j < N; j++) {
      if (A[j] == BC[i].first) A[j] = BC[i].second;
    }
    res.emplace_back(accumulate(A.begin(), A.end(), 0));
  }
  for (int i = 0; i < Q; i++) {
    cout << res[i] << endl;
    ;
  }
}
