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