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