#include <bits/stdc++.h>
using namespace std;
int main() {
  ios::sync_with_stdio(false);
  int N;
  cin >> N;
  int A[N];
  int somme = 0;
  for (int i = 0; i < N; i++) {
    cin >> A[i];
    somme += A[i];
  }
  int Q;
  cin >> Q;
  for (int j = 0; j < Q; j++) {
    int b, c;
    cin >> b >> c;
    for (int k = 0; k < N; k++) {
      if (A[k] == b) {
        somme += (c - b);
        A[k] = c;
      }
    }
    cout << somme << "\n";
  }
}
