#include <bits/stdc++.h>
using namespace std;
int main() {
  int N;
  cin >> N;
  vector<int> A(N);
  for (int i = 0; i < N; i++) {
    cin >> A[i];
  }
  int Q;
  cin >> Q;
  vector<vector<int>> B(2, vector<int>(Q));
  for (int i = 0; i < Q; i++) {
    cin >> B[0][i] >> B[1][i];
  }
  int ans = 0;
  for (int i = 0; i < N; i++) {
    ans += A[i];
  }
  int check = 0;
  for (int i = 0; i < Q; i++) {
    for (int j = 0; j < N; j++) {
      if (A[j] == B[0][i]) {
        check++;
        A[j] = B[1][i];
      }
    }
    ans += (B[1][i] - B[0][i]) * check;
    if (check != 0) check = 0;
    cout << ans << endl;
  }
}
