#include <bits/stdc++.h>
using namespace std;
int n, q, a, b, c;
long long s;
map<int, int> m;
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; ++i) {
    scanf("%d", &a);
    ++m[a];
    s += a;
  }
  scanf("%d", &q);
  for (int i = 1; i <= q; ++i) {
    scanf("%d%d", &b, &c);
    m[c] += m[b];
    s += (c - b) * m[b];
    m[b] = 0;
    printf("%d\n", s);
  }
  return 0;
}
