#include <bits/stdc++.h>
using namespace std;
const long long INF = (long long)1e12;
const long long mod = (long long)1e9 + 7;
struct UnionFind {
  vector<long long> par;
  UnionFind(long long N) : par(N) {
    for (long long i = 0; i < N; i++) par[i] = i;
  }
  long long root(long long x) {
    if (par[x] == x) return x;
    return par[x] = root(par[x]);
  }
  void unite(long long x, long long y) {
    long long rx = root(x);
    long long ry = root(y);
    if (rx == ry) return;
    par[rx] = ry;
  }
  bool same(long long x, long long y) {
    long long rx = root(x);
    long long ry = root(y);
    return rx == ry;
  }
};
long long gcd(long long a, long long b) {
  if (a % b == 0) return b;
  return gcd(b, a % b);
}
signed main() {
  long long n;
  cin >> n;
  vector<long long> a(n + 1);
  for (long long i = 0; i < n; i++) {
    long long t;
    cin >> t;
    a[t]++;
  }
  vector<long long> sum(n + 2);
  for (long long i = 0; i < n; i++) {
    sum[i + 2] = sum[i + 1] + a[i + 1] * (i + 1);
  }
  long long ans = sum[n + 1];
  long long q;
  cin >> q;
  for (long long _ = 0; _ < q; _++) {
    long long b, c;
    cin >> b >> c;
    ans += (c - b) * a[b];
    a[c] += a[b];
    a[b] = 0;
    cout << ans << endl;
  }
}
