#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  scanf("%d", &n);
  int a[n];
  for (int i = 0; i < n; i++) {
    scanf("%d", &a[i]);
  }
  int q;
  scanf("%d", &q);
  while (q--) {
    int b, c;
    scanf("%d%d", &b, &c);
    int sum = 0;
    for (int i = 0; i < n; i++) {
      if (a[i] == b) a[i] = c;
    }
    sum = accumulate(a, a + n, sum);
    printf("%d\n", sum);
  }
  return 0;
}
