#include <bits/stdc++.h>
using namespace std;
int main() {
  long long N;
  cin >> N;
  vector<int> A(N);
  int count = N;
  for (int i = 0; i < count; i++) {
    cin >> A.at(i);
  }
  long long Q;
  cin >> Q;
  vector<long long> B(Q);
  vector<long long> C(Q);
  vector<long long> S(Q);
  count = Q;
  for (int i = 0; i < count; i++) {
    cin >> B.at(i) >> C.at(i);
  }
  count = Q;
  for (int i = 0; i < Q; i++) {
    for (int j = 0; j < N; j++) {
      S.at(i) += A.at(j);
    }
  }
  vector<long long> num(Q);
  for (int i = 0; i < Q; i++) {
    for (int j = 0; j < N; j++) {
      if (A.at(j) == B.at(i)) {
        A.at(j) = C.at(i);
        num.at(i)++;
      }
    }
  }
  for (int i = 0; i < count; i++) {
    S.at(i) += (C.at(i) - B.at(i)) * num.at(i);
    cout << S.at(i) << endl;
  }
}
