#include <bits/stdc++.h>
int gcd(int a, int b) {
  if (a < b) {
    int now = a;
    a = b;
    b = a;
  }
  int r = a % b;
  while (r != 0) {
    a = b;
    b = r;
    r = a % b;
  }
  return b;
}
void swap(int *x, int *y) {
  int temp;
  temp = *x;
  *x = *y;
  *y = temp;
}
int partition(int array[], int left, int right) {
  int i, j, pivot;
  i = left;
  j = right + 1;
  pivot = left;
  do {
    do {
      i++;
    } while (array[i] < array[pivot]);
    do {
      j--;
    } while (array[pivot] < array[j]);
    if (i < j) {
      swap(&array[i], &array[j]);
    }
  } while (i < j);
  swap(&array[pivot], &array[j]);
  return j;
}
void quick_sort(int array[], int left, int right) {
  int pivot;
  if (left < right) {
    pivot = partition(array, left, right);
    quick_sort(array, left, pivot - 1);
    quick_sort(array, pivot + 1, right);
  }
}
int main(void) {
  int n;
  scanf("%d", &n);
  int A[200000];
  int i;
  int all = 0;
  for (i = 0; i < n; i++) {
    int now;
    scanf("%d", &now);
    A[now]++;
    all += now;
  }
  int q;
  scanf("%d", &q);
  while (q--) {
    int b, c;
    scanf("%d%d", &b, &c);
    all -= b * A[b];
    all += c * A[b];
    A[c] += A[b];
    A[b] = 0;
    printf("%d\n", all);
  }
}
