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