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