#include <bits/stdc++.h>
using namespace std;
const int MAX = 2e3 + 3;
const int mod = 1e9 + 7;
long long int a[100010], f[100010];
int n, q;
int main() {
  scanf("%d", &n);
  long long int s = 0;
  for (int i = (int)0; i < (int)n; i++)
    scanf("%lld", &a[i]), f[a[i]]++, s += a[i];
  int b, c;
  scanf("%d", &q);
  while (q--) {
    scanf("%d %d", &b, &c);
    s -= (long long int)f[b] * b;
    s += (long long int)f[b] * c;
    f[c] += f[b];
    printf("%lld\n", s);
  }
  return 0;
}
