#include <bits/stdc++.h>
using namespace std;
inline int read() {
  int sgn = 1;
  int ans = 0;
  char ch;
  ch = getchar();
  while (ch < '0' || ch > '9') {
    if (ch == '-') sgn = -1;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9') {
    ans = (ans << 3) + (ans << 1) + (ch ^ 48), ch = getchar();
  }
  return ans;
}
inline void write(long long x) {
  if (x < 0) putchar('-'), x = -x;
  if (x > 9) write(x / 10);
  putchar(x % 10 + '0');
}
int main() {
  long long n, q;
  map<long long, long long> m;
  n = read();
  for (long long i = 0; i < n; i++) {
    long long x;
    x = read();
    m[x]++;
  }
  q = read();
  while (q--) {
    long long b, c;
    long long sum = 0;
    scanf("%lld%lld", &b, &c);
    m[c] += m[b];
    m.erase(b);
    for (map<long long, long long>::iterator it = m.begin(); it != m.end();
         it++) {
      sum += (it->first) * (it->second);
    }
    write(sum);
    putchar('\n');
  }
}
