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