#include <bits/stdc++.h>
using namespace std;
long long int bigmod(long long int a, long long int e) {
  long long int ret = 1LL;
  while (e > 0) {
    if (e % 2 == 1) ret = ret * a % (long long int)(1e9 + 7);
    a = a * a % (long long int)(1e9 + 7);
    e /= 2;
  }
  return ret;
}
int vis[1000000];
int solve() {
  int n;
  cin >> n;
  int ar[n];
  int sum = 0;
  for (int i = 0; i < n; i++) {
    cin >> ar[i];
    vis[ar[i]]++;
    sum += ar[i];
  }
  int q;
  cin >> q;
  while (q--) {
    int a, b;
    cin >> a >> b;
    sum -= a * vis[a];
    sum += b * vis[a];
    vis[b] = vis[a] + vis[b];
    vis[a] = 0;
    cout << sum << endl;
  }
  return 0;
}
int main() {
  int t = 1;
  while (t--) {
    int x = solve();
  }
  return 0;
}
