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