#include <bits/stdc++.h>
using namespace std;
int main() {
  int N;
  cin >> N;
  vector<int64_t> A(N);
  for (int i = 0; i < N; i++) {
    cin >> A.at(i);
  }
  int Q;
  cin >> Q;
  int B, C;
  int cnt = 0;
  int tot0 = accumulate(A.begin(), A.end(), 0);
  int tot1 = 0;
  for (int i = 0; i < Q; i++) {
    cin >> B >> C;
    cnt = count(A.begin(), A.end(), B);
    replace(A.begin(), A.end(), B, C);
    tot1 = tot0 + cnt * (C - B);
    cout << tot1 << endl;
    tot0 = tot1;
  }
}
