#include <bits/stdc++.h>
void replace(int *a, int b, int c, int q) {
  for (int i = 0; i < q; ++i) {
    if (a[i] == b) a[i] = c;
  }
}
int sum(int *a, int q) {
  int s = 0;
  for (int i = 0; i < q; ++i) s += a[i];
  return s;
}
int main() {
  int n, q;
  scanf("%d", &n);
  int a[n];
  for (int i = 0; i < n; ++i) scanf("%d", &a[i]);
  scanf("%d", &q);
  int b, c;
  for (int i = 0; i < q; ++i) {
    scanf("%d%d", &b, &c);
    replace(a, b, c, n);
    printf("%d\n", sum(a, n));
  }
  return 0;
}
