#include <bits/stdc++.h>
using namespace std;
int n, q, b, c;
int main() {
  cin >> n;
  vector<int> a(n);
  for (int i = 0; i < n; i++) {
    cin >> a.at(i);
  }
  cin >> q;
  for (int j = 0; j < q; j++) {
    cin >> b >> c;
    long result, i = 0;
    for (int k : a) {
      if (k == b) {
        k = c;
        a.at(i) = c;
      }
      result += k;
      i++;
    }
    cout << result << endl;
    result = 0;
  }
}
