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