#include <bits/stdc++.h>
using namespace std;
const long long INF = 1e5 + 5;
long long n, num[INF], q;
long long sum;
signed main() {
  scanf("%lld", &n);
  for (long long i = 1; i <= n; i++) {
    long long x = 0;
    scanf("%lld", &x);
    sum += x;
    num[x]++;
  }
  scanf("%lld", &q);
  while (q--) {
    long long x = 0, y = 0;
    scanf("%lld %lld", &x, &y);
    num[y] += num[x];
    sum += (y - x) * num[x];
    cout << sum << "\n";
  }
  return 0;
}
