#include <bits/stdc++.h>
int main() {
  int i, n;
  scanf("%d", &n);
  int a[n];
  for (i = 0; i < n; i++) {
    scanf("%d", &a[i]);
  }
  int q, c, d;
  scanf("%d", &q);
  long long int s = 0;
  while (q != 0) {
    if (q == 0) {
      break;
    }
    scanf("%d%d", &c, &d);
    for (i = 0; i < n; i++) {
      if (a[i] == c) {
        a[i] = d;
      }
      s = s + a[i];
    }
    printf("%lld\n", s);
    s = 0;
    q = q - 1;
  }
}
