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