#include <bits/stdc++.h>
using namespace std;
int main() {
  int N;
  cin >> N;
  vector<int> A;
  for (int i = 0; i < N; i++) {
    int tmp;
    cin >> tmp;
    A.push_back(tmp);
  }
  int Q;
  cin >> Q;
  long long ans = 0;
  for (int i = 0; i < Q; i++) {
    int b, c;
    cin >> b >> c;
    for (int j = 0; j < N; j++) {
      if (A[j] == b) {
        A[j] = c;
      }
      ans += A[j];
    }
    cout << ans << endl;
    ans = 0;
  }
}
