#include <bits/stdc++.h>
using namespace std;
const int inf = 0x3f3f3f3f;
const int mod = 1000000007;
const int maxn = 1000005;
inline int read() {
  int x = 0, f = 1;
  char c = getchar();
  for (; !isdigit(c); c = getchar())
    if (c == '-') f = -1;
  for (; isdigit(c); c = getchar()) x = x * 10 + c - '0';
  return x * f;
}
int flag[maxn];
int main() {
  int n;
  cin >> n;
  vector<int> v(n + 1);
  int sum = 0;
  for (int i = 1; i <= n; i++) cin >> v[i], sum += v[i], flag[v[i]]++;
  int q = read();
  while (q--) {
    int a = read(), b = read();
    sum -= a * flag[a];
    sum += b * flag[a];
    flag[b] += flag[a];
    flag[a] = 0;
    cout << sum << endl;
  }
}
