#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 5;
int num[N], s[N];
int n, k, x, b, c, sum, count1;
int main() {
  scanf("%d", &n);
  for (int i = 0; i < n; i++) {
    scanf("%d", &x);
    num[x]++;
    sum += x;
  }
  scanf("%d", &k);
  for (int i = 0; i < k; i++) {
    scanf("%d%d", &b, &c);
    count1 = num[b];
    sum -= count1 * b;
    sum += count1 * c;
    num[b] -= count1;
    num[c] += count1;
    printf("%d\n", sum);
  }
}
