#include <bits/stdc++.h>
using namespace std;
int main() {
  long long N;
  cin >> N;
  map<long long, long long> a;
  for (int i = 0; i < N; i++) {
    int c;
    cin >> c;
    if (a.count(c)) {
      a[c]++;
    } else {
      a[c] = 1;
    }
  }
  long long M;
  cin >> M;
  for (int i = 0; i < M; i++) {
    long long sum = 0, d, e;
    cin >> d >> e;
    if (a.count(d)) {
      if (a.count(e)) {
        a[e] += a[d];
        a.erase(d);
      } else {
        a[e] = a[d];
        a.erase(d);
      }
    }
    for (pair<long long, long long> p : a) {
      long long p1 = p.first;
      long long p2 = p.second;
      sum += p1 * p2;
    }
    cout << sum << endl;
  }
}
