#include <bits/stdc++.h>
using namespace std;
int main() {
  int N, Q;
  cin >> N;
  vector<int> A(N);
  for (int i = 0; i < N; i++) cin >> A.at(i);
  cin >> Q;
  vector<vector<int>> B(Q, vector<int>(2));
  for (int i = 0; i < Q; i++) {
    int64_t h = 0;
    for (int j = 0; j < 2; j++) {
      cin >> B.at(i).at(j);
    }
    for (int k = 0; k < N; k++) {
      if (A.at(k) == B.at(i).at(0)) A.at(k) = B.at(i).at(1);
      h += A.at(k);
    }
    cout << h << endl;
  }
}
