#include <bits/stdc++.h>
using namespace std;
int main() {
  long long n, x, a[100005], q, b, c, ans = 0;
  cin >> n;
  for (long long i = 0; i < 100005; i++) {
    a[i] = 0;
  }
  for (long long i = 0; i < n; i++) {
    cin >> x;
    a[x]++;
  }
  cin >> q;
  for (long long i = 0; i < q; i++) {
    ans = 0;
    cin >> b >> c;
    a[c] += a[b];
    a[b] = 0;
    for (long long i = 0; i < 100005; i++) {
      ans += i * a[i];
    }
    cout << ans << endl;
  }
}
