#include <bits/stdc++.h>
using namespace std;
int main() {
  long long n, q;
  map<long long, long long> m;
  cin >> n;
  for (long long i = 0; i < n; i++) {
    long long x;
    scanf("%lld", &x);
    m[x]++;
  }
  cin >> q;
  while (q--) {
    long long b, c;
    long long sum = 0;
    scanf("%lld%lld", &b, &c);
    m[c] += m[b];
    m[b] = 0;
    for (map<long long, long long>::iterator it = m.begin(); it != m.end();
         it++) {
      sum += (it->first) * (it->second);
    }
    printf("%lld\n", sum);
  }
}
