#include <bits/stdc++.h>
using namespace std;
const int mod = 1000000007;
inline int read() {
  int x = 0, w = 1;
  char ch = 0;
  while (ch < '0' || ch > '9') {
    if (ch == '-') w = -1;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9') {
    x = x * 10 + (ch - '0');
    ch = getchar();
  }
  return x * w;
}
int main() {
  int _ = 1;
  while (_--) {
    int num[100000] = {0};
    int q, n, x, sum = 0;
    n = read();
    for (int i = 0; i < n; ++i) {
      x = read();
      num[x]++;
      sum += x;
    }
    q = read();
    while (q--) {
      int a, b;
      a = read();
      b = read();
      num[b] += num[a];
      sum += num[a] * (b - a);
      num[a] = 0;
      printf("%d\n", sum);
    }
  }
  return 0;
}
