#include <bits/stdc++.h>
using namespace std;
int main() {
  int t, n, a;
  cin >> n;
  vector<int> v(n);
  for (int i = 0; i < n; i++) {
    cin >> a;
    v.push_back(a);
  }
  cin >> t;
  while (t--) {
    int x = 0, y = 0, s = 0;
    cin >> x >> y;
    for (int i = 0; i < n; i++) {
      if (v[i] == x) {
        v[i] = y;
      }
      s = s + v[i];
    }
    cout << s << "\n";
  }
  return 0;
}
