#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  scanf("%d", &n);
  vector<int> seq_a(n, 0);
  for (int i = 0; i < n; i++) {
    scanf("%d", &seq_a.at(i));
  }
  int q;
  scanf("%d", &q);
  vector<int> answer(q, 0);
  for (int i = 0; i < q; i++) {
    int b, c;
    scanf("%d%d", &b, &c);
    int sum = 0;
    for (int j = 0; j < n; j++) {
      if (seq_a.at(j) == b) {
        seq_a.at(j) = c;
      }
      sum += seq_a.at(j);
    }
    answer.at(i) = sum;
  }
  for (int ans : answer) {
    printf("%d\n", ans);
  }
}
