#include <bits/stdc++.h>
using namespace std;
const int inf = 1000000000;
const int mod = 1000000007;
const int nil = -1;
int i, n, m, k, ans, q, b, c;
int a[100001];
int main() {
  for (i = 0; i < 100001; i++) a[i] = 0;
  scanf(" %d", &n);
  for (i = 0; i < n; i++) {
    scanf(" %d", &k);
    a[k]++;
  }
  int sum = 0;
  for (i = 0; i < 100001; i++) sum += i * a[i];
  scanf(" %d", &q);
  for (i = 0; i < q; i++) {
    scanf(" %d %d", &b, &c);
    sum += (c - b) * a[b];
    printf("%d\n", sum);
    a[c] += a[b];
    a[b] = 0;
  }
}
