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