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