#include <bits/stdc++.h>
using namespace std;
int main(int argc, const char *argv[]) {
  int N;
  cin >> N;
  int *A = new int[N];
  for (int i = 0; i < N; ++i) {
    cin >> A[i];
  }
  int Q;
  cin >> Q;
  auto *S = new unsigned long int[Q];
  auto *B = new int[Q];
  auto *C = new int[Q];
  for (int qi = 0; qi < Q; ++qi) {
    cin >> B[qi] >> C[qi];
  }
  for (int qi = 0; qi < Q; ++qi) {
    if (qi == 0) {
      S[0] = 0;
      for (int ni = 0; ni < N; ++ni) {
        S[0] += A[ni];
      }
    } else {
      S[qi] = S[qi - 1];
    }
    for (int ni = 0; ni < N; ++ni) {
      int diff = C[qi] - B[qi];
      if (A[ni] == B[qi]) {
        S[qi] += diff;
        A[ni] += diff;
      }
    }
  }
  for (int i = 0; i < Q; ++i) {
    cout << S[i] << endl;
  }
  delete[] A, B, C;
  delete[] S;
  return 0;
}
