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