#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main() {
  int N;
  cin >> N;
  vector<int> A(N);
  for (int i = 0; i < N; i++) {
    cin >> A.at(i);
  }
  int Q;
  cin >> Q;
  for (int i = 0; i < Q; i++) {
    int from, to;
    cin >> from >> to;
    int ans = 0;
    for (int i = 0; i < N; i++) {
      if (A.at(i) == from) {
        A.at(i) = to;
        ans += to;
      } else {
        ans += A.at(i);
      }
    }
    cout << ans << endl;
  }
  return 0;
}
