#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;
int main() {
  map<int, int> m;
  long long int sum = 0;
  int t, n;
  cin >> n;
  for (int i = 0; i < (n); ++i) {
    cin >> t;
    m[t]++;
    sum += t;
  }
  int q, b, c;
  cin >> q;
  for (int i = 0; i < (q); ++i) {
    cin >> b >> c;
    sum -= m[b] * b;
    sum += m[b] * c;
    m[c] += m[b];
    m[b] = 0;
    printf("%lld\n", sum);
  };
  return 0;
}
