#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<int>;
using mpii = map<int, int>;
using si = set<int>;
using sll = set<ll>;
using vll = vector<ll>;
ll ar[100100];
int main() {
  ll n, p, q, a, b, sum = 0;
  cin >> n;
  for (int i = 0; i <= n - 1; i++) {
    scanf("%d", &p);
    sum += p;
    ar[p]++;
  }
  scanf("%lld", &q);
  while (q--) {
    scanf("%lld%lld", &a, &b);
    ll dif = b - a;
    ll to = ar[a] * dif;
    ar[b] += ar[a];
    ar[a] = 0;
    sum += to;
    printf("%lld", sum);
    printf("\n");
  }
  return 0;
}
