#include <bits/stdc++.h>
using namespace std;
int main(void) {
  int N;
  cin >> N;
  vector<long long> a(N);
  long long sum = 0;
  for (int i = 0; i < N; i++) {
    cin >> a[i];
    sum += a[i];
  }
  sort((a).begin(), (a).end());
  int Q;
  cin >> Q;
  long long B, C;
  for (int i = 0; i < Q; i++) {
    cin >> B >> C;
    long long diff = C - B;
    int flag = 0;
    for (int j = 0; j < N; j++) {
      if (a[j] == B) {
        a[j] = C;
        sum += diff;
        flag = 1;
      } else {
        if (flag == 1) continue;
      }
    }
    cout << sum << "\n";
  }
}
