#include <bits/stdc++.h>
using namespace std;
long long n, i, q, sum, curr, a, b;
unordered_map<long long, long long> table;
int main() {
  scanf("%lld\n", &n);
  table.rehash(n);
  sum = 0;
  for (i = 0; i < n; i++) {
    scanf("%lld", &curr);
    if (table.find(curr) == table.end()) {
      table[curr] = 1;
    } else {
      table[curr]++;
    }
    sum += curr;
  }
  scanf("%lld\n", &q);
  while (q--) {
    scanf("ll%d %lld\n", &a, &b);
    if (table.find(a) == table.end() || table[a] == 0) {
      continue;
    } else {
      sum += (b - a) * table[a];
      if (table.find(b) == table.end()) {
        table[b] = table[a];
      } else {
        table[b] += table[a];
      }
      table[a] = 0;
    }
    printf("%lld\n", sum);
  }
  return 0;
}
