#include <bits/stdc++.h>
using namespace std;
int main() {
  int N, Q;
  vector<int> A;
  vector<int> B;
  vector<int> C;
  int i, j;
  long int S;
  vector<long int> S_sum;
  cin >> N;
  S = 0;
  for (i = 0; i < N; i++) {
    int ai;
    cin >> ai;
    A.push_back(ai);
    S += ai;
  }
  cin >> Q;
  for (i = 0; i < Q; i++) {
    long int bi, ci;
    cin >> bi >> ci;
    for (j = 0; j < N; j++) {
      if (A[j] == bi) {
        S = S + ci - bi;
        A[j] = ci;
      }
    }
    S_sum.push_back(S);
  }
  for (i = 0; i < Q; i++) {
    cout << S_sum[i] << endl;
  }
}
