#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, sum = 0;
  scanf("%d", &n);
  int num[100005] = {0};
  int book[100005] = {0};
  for (int i = 1; i <= n; i++) {
    scanf("%d", &num[i]);
    book[num[i]]++;
    sum += num[i];
  }
  int q;
  scanf("%d", &q);
  while (q--) {
    int b, c;
    scanf("%d %d", &b, &c);
    if (book[b] == 0) {
      printf("%d\n", sum);
      continue;
    } else {
      book[c] += book[b];
      sum = sum + (c - b) * book[b];
      book[b] = 0;
      printf("%d\n", sum);
      continue;
    }
  }
  return 0;
}
