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