#include <bits/stdc++.h>
using namespace std;
long long read() {
  long long ans = 0;
  char last = ' ', ch = getchar();
  while (ch < '0' || ch > '9') last = ch, ch = getchar();
  while (ch >= '0' && ch <= '9') ans = ans * 10 + ch - '0', ch = getchar();
  if (last == '-') ans = -ans;
  return ans;
}
long long m[100005] = {0};
int n = read(), q, sum;
int main() {
  for (int i = 1; i <= n; i++) {
    int temp = read();
    m[temp]++;
    sum += temp;
  }
  q = read();
  for (int i = 1; i <= q; i++) {
    int a = read(), b = read();
    sum += m[a] * (b - a);
    m[b] += m[a];
    m[a] = 0;
    cout << sum << endl;
  }
}
