#include <bits/stdc++.h>
#pragma GCC target("avx")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
using namespace std;
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n;
  cin >> n;
  vector<int64_t> a(100005);
  for (int i = 0; i < n; i++) {
    int k;
    cin >> k;
    a[k]++;
  }
  int q;
  cin >> q;
  for (int i = 0; i < q; i++) {
    int64_t b, c;
    cin >> b >> c;
    a[c] += a[b];
    a[b] = 0;
    int64_t res = 0;
    for (int j = 0; j < 100005; j++) res += a[j] * j;
    cout << res << "\n";
  }
  return 0;
}
