#include <bits/stdc++.h>
long int org_array[100000];
long int q_array[100000][2];
long int conver_array[100000];
long long int a_array[100000];
int main() {
  long int n, q;
  long int max_num = 0;
  long long int sum = 0;
  scanf("%ld", &n);
  for (long int i = 0; i < n; i++) {
    scanf("%ld", &org_array[i]);
    if (org_array[i] > max_num) {
      max_num = org_array[i];
    }
  }
  scanf("%ld", &q);
  for (long int i = 0; i < q; i++) {
    scanf("%ld %ld", &q_array[i][0], &q_array[i][1]);
  }
  for (long int i = 0; i <= 100000; i++) {
    conver_array[i] = 0;
  }
  for (long int i = 0; i < n; i++) {
    conver_array[org_array[i]]++;
  }
  for (long int i = 0; i < n; i++) {
    sum += org_array[i];
  }
  for (long int i = 0; i < q; i++) {
    long int move_index = 0;
    move_index = conver_array[q_array[i][0]];
    conver_array[q_array[i][1]] += move_index;
    conver_array[q_array[i][0]] = 0;
    sum += move_index * q_array[i][1];
    sum -= move_index * q_array[i][0];
    a_array[i] = sum;
  }
  for (int i = 0; i < q; i++) {
    printf("%lld\n", a_array[i]);
  }
  return 0;
}
