#include <bits/stdc++.h>
using namespace std;
map<int, int> mym;
int res[100005];
int main() {
  int N;
  cin >> N;
  long long int sum = 0;
  for (int i = 0; i < N; i++) {
    int t;
    cin >> t;
    sum += t;
    mym[t]++;
  }
  int Q;
  cin >> Q;
  for (int i = 0; i < Q; i++) {
    long long int b, c;
    cin >> b >> c;
    sum -= mym[b] * b;
    sum += mym[b] * c;
    mym[c] += mym[b];
    mym[b] = 0;
    res[i] = sum;
  }
  for (int i = 0; i < Q; i++) cout << res[i] << endl;
  return 0;
}
