#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, val, q;
  cin >> n;
  vector<int> a;
  int b, c;
  for (int i = 0; i < n; i++) {
    cin >> val;
    a.push_back(val);
  }
  cin >> q;
  for (int i = 0; i < q; i++) {
    int sum = 0;
    cin >> b >> c;
    for (int i = 0; i < n; i++) {
      if (a[i] == b) {
        a[i] = c;
      }
      sum += a[i];
    }
    cout << sum << endl;
  }
  return 0;
}
