#include <bits/stdc++.h>
using namespace std;
int main() {
  long long n, q;
  cin >> n;
  vector<long long> A;
  vector<long long> B;
  vector<long long> C;
  vector<long long> S;
  for (int i = 0; i < n; i++) {
    int k;
    cin >> k;
    A.emplace_back(k);
  }
  cin >> q;
  for (int i = 0; i < q; i++) {
    long long b, c;
    cin >> b >> c;
    B.emplace_back(b);
    C.emplace_back(c);
    long long sum = 0;
    for (int j = 0; j < A.size(); j++) {
      if (A[j] == B[i]) {
        A[j] = C[i];
      }
      sum += A[j];
    }
    S.emplace_back(sum);
  }
  for (int i = 0; i < S.size(); i++) {
    cout << S[i] << endl;
  }
  return 0;
}
