#include <bits/stdc++.h>
using namespace std;
int main() {
  int N;
  long long ans = 0;
  cin >> N;
  vector<int> A(100005);
  for (int i = 0; i < (int)(N); i++) {
    int tmp;
    cin >> tmp;
    A[tmp]++;
    ans += tmp;
  }
  int Q;
  cin >> Q;
  for (int i = 0; i < (int)(Q); i++) {
    int B, C;
    cin >> B >> C;
    int cnt = A[B];
    A[B] = 0;
    ans -= B * cnt;
    ans += C * cnt;
    A[C] += cnt;
    cout << ans << endl;
  }
  return 0;
}
