#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;
int main() {
  int N;
  cin >> N;
  vector<int> A;
  for (int i = 0; i < (N); ++i) {
    int num;
    cin >> num;
    A.push_back(num);
  }
  int Q;
  cin >> Q;
  int B[Q], C[Q];
  for (int i = 0; i < (Q); ++i) {
    cin >> B[i] >> C[i];
  }
  long long ans = accumulate(A.begin(), A.end(), 0LL);
  for (int i = 0; i < (Q); ++i) {
    int tag_cnt = count(A.begin(), A.end(), B[i]);
    replace(A.begin(), A.end(), B[i], C[i]);
    ans = ans + (C[i] - B[i]) * tag_cnt;
    cout << ans << endl;
  }
  return 0;
}
