#include <bits/stdc++.h>
using namespace std;
int main() {
  int N, Q, B, C;
  cin >> N;
  vector<int> A(N);
  for (int i = 0; i < N; i++) {
    int a;
    cin >> a;
    A[i] = a;
  }
  cin >> Q;
  int count_B;
  for (int i = 0; i < Q; i++) {
    cin >> B >> C;
    count_B = count(A.begin(), A.end(), B);
    if (count_B != 0) {
      replace(A.begin(), A.end(), B, C);
    }
    cout << accumulate(A.begin(), A.end(), 0) << endl;
  }
}
