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