#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  scanf("%d", &n);
  int arr[100000];
  fill_n(arr, 100000, 0);
  int i;
  int input;
  long long int sum = 0;
  for (i = 0; i < n; i++) {
    scanf("%d", &input);
    arr[input - 1] = arr[input - 1] + 1;
    sum = sum + input;
  }
  int q;
  scanf("%d", &q);
  int old_val, new_val;
  while (q--) {
    scanf("%d", &old_val);
    scanf("%d", &new_val);
    sum = ((new_val - old_val) * arr[old_val - 1]) + sum;
    printf("%d\n", sum);
    arr[new_val - 1] = arr[new_val - 1] + arr[old_val - 1];
    arr[old_val - 1] = 0;
  }
}
