#include <bits/stdc++.h>
using namespace std;
int main() {
  int freq[100001] = {0};
  int n;
  scanf("%d", &n);
  int arr[n];
  for (int a = 0; a < n; a++) scanf("%d ", &arr[a]);
  for (int a = 0; a < n; a++) freq[arr[a]]++;
  int sum = accumulate(arr, arr + n, 0);
  int q;
  scanf("%d ", &q);
  while (q--) {
    int b, c;
    scanf("%d %d", &b, &c);
    sum += (c - b) * freq[b];
    freq[c] += freq[b];
    printf("%d\n", sum);
  }
}
