#include <bits/stdc++.h>
using namespace std;
using P = pair<long long, long long>;
using V = vector<long long>;
void solve_abc_d() {
  long long n, m;
  long long k;
  long long l_ans = 0;
  cin >> n;
  map<long long, long long> a;
  long long tmp;
  for (long long i = 0; i < (long long)(n); i++) {
    cin >> tmp;
    ++a[tmp];
  }
  long long q;
  cin >> q;
  long long b, c;
  vector<unsigned long long> sum(q, 0);
  for (long long i = 0; i < (long long)(q); i++) {
    cin >> b >> c;
    a[c] += a[b];
    a[b] = 0;
    sum[i] = 0;
    for (auto itr = a.begin(); itr != a.end(); itr++) {
      sum[i] += itr->first * itr->second;
    }
  }
  for (long long i = 0; i < (long long)(q); i++) {
    cout << sum[i] << "\n";
  }
  return;
}
int main(void) {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed;
  cout << setprecision(15);
  solve_abc_d();
  return 0;
}
