#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, q, b, c, sum, h, i;
  cin >> n;
  vector<int> vec(n);
  for (int i = 0; i < n; i++) {
    cin >> vec.at(i);
  }
  cin >> q;
  while (h < q) {
    cin >> b >> c;
    while (i < n) {
      if (vec.at(i) == b) vec.at(i) = c;
      sum += vec.at(i);
      i++;
    }
    cout << sum << endl;
    h++;
    sum = 0;
    i = 0;
  }
}
