#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  while (scanf("%d", &n) != EOF) {
    int i, j;
    int a, sum;
    int f[100005];
    sum = 0;
    memset(f, 0, sizeof(f));
    for (i = 0; i < n; i++) {
      scanf("%d", &a);
      sum += a;
      f[a]++;
    }
    int q;
    scanf("%d", &q);
    while (q--) {
      int b, c;
      int d;
      scanf("%d%d", &b, &c);
      if (f[b] > 0) {
        d = c - b;
        sum = sum + (d * f[b]);
        f[c] += f[b];
        f[b] = 0;
      }
      printf("%d\n", sum);
    }
  }
  return (0);
}
