#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>;
int ar[100100];
int main() {
  int 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("%d", &q);
  while (q--) {
    scanf("%d%d", &a, &b);
    int dif = b - a;
    int to = ar[a] * dif;
    ar[b] += ar[a];
    ar[a] = 0;
    sum += to;
    printf("%d", sum);
    printf("\n");
  }
  return 0;
}
