#include <bits/stdc++.h>
using namespace std;
int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  long long t = 1;
  while (t--) {
    long long n, q;
    cin >> n;
    long long a[n];
    long long sum = 0;
    long long mp[100001];
    memset(mp, 0, sizeof(mp));
    for (long long i = 0; i < n; ++i) {
      cin >> a[i];
      sum += a[i];
      mp[a[i]]++;
    }
    cin >> q;
    while (q--) {
      long long val = 0;
      long long a, b;
      cin >> a >> b;
      long long dif = b - a;
      if (mp[a] > 0) val = mp[a];
      sum += val * dif;
      mp[b] = mp[a];
      mp[a] = 0;
      cout << sum << "\n";
    }
  }
}
