#include <bits/stdc++.h>
using namespace std;
const int mod = 1e9 + 7;
long long mod_pow(long long a, long long n, long long mod) {
  long long res = 1;
  while (n) {
    if (n & 1) res = (res * a) % mod;
    n /= 2;
    a = (a * a) % mod;
  }
  return res;
}
void solve();
int main() {
  ios::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  solve();
}
const int maxn = 1e5 + 2;
int a[maxn];
void solve() {
  long long n;
  cin >> n;
  long long sum = 0;
  for (int i = 0; i < n; ++i) {
    long long x;
    cin >> x;
    ++a[x];
    sum += x;
  }
  long long q;
  cin >> q;
  while (q--) {
    int x, y;
    cin >> x >> y;
    sum -= a[x] * x;
    sum += a[x] * y;
    a[y] += a[x];
    a[x] = 0;
    cout << sum << "\n";
  }
}
