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