#include <bits/stdc++.h>
using namespace std;
const int MAXN = 1e5 + 5;
long long ans;
int n, m;
int a, t[MAXN];
inline int read() {
  int tot = 0, f = 1;
  char c = getchar();
  while (c < '0' || c > '9') {
    if (c == '-') f = -1;
    c = getchar();
  }
  while (c >= '0' && c <= '9') {
    tot = (tot << 1) + (tot << 3) + (c ^ 48);
    c = getchar();
  }
  return tot * f;
}
signed main() {
  n = read();
  for (int i = 1; i <= n; i++) {
    a = read();
    t[a]++;
    ans += a;
  }
  m = read();
  for (int i = 1; i <= m; i++) {
    int x = read(), y = read();
    ans += (y - x) * t[x];
    t[y] += t[x];
    t[x] = 0;
    cout << ans << endl;
  }
  return 0;
}
