#include <bits/stdc++.h>
int up_comp(const void *a, const void *b) { return *(int *)a - *(int *)b; }
int down_comp(const void *a, const void *b) { return *(int *)b - *(int *)a; }
int int_sort(const void *a, const void *b) {
  return strcmp((char *)a, (char *)b);
}
int count_digit(int a) {
  int i = 0;
  while (a != 0) {
    a = a / 10;
    i++;
  }
  return i;
}
int euclid(int a, int b) {
  int temp;
  if (a < b) {
    temp = a;
    a = b;
    b = temp;
  }
  if (b < 1) return -1;
  if (a % b == 0) return b;
  return euclid(b, a % b);
}
int main(void) {
  int n, a[100002], q, b[100002], c[100002];
  int kaku[100002];
  int sum = 0;
  scanf("%d", &n);
  for (int i = 0; i < (n + 1); ++i) {
    kaku[i] = 0;
  }
  for (int i = 0; i < (n); ++i) {
    scanf("%d", &a[i]);
    sum += a[i];
    kaku[a[i]]++;
  }
  scanf("%d", &q);
  for (int i = 0; i < (q); ++i) {
    scanf("%d%d", &b[i], &c[i]);
  }
  for (int i = 0; i < (q); ++i) {
    sum = sum + (c[i] - b[i]) * kaku[b[i]];
    kaku[c[i]] = kaku[b[i]] + kaku[c[i]];
    kaku[b[i]] = 0;
    printf("%d\n", sum);
  }
  return 0;
}
