#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  long long int n, q, old_val = 0, new_val = 0;
  cin >> n;
  int a[n];
  for (int i = 0; i < n; i++) cin >> a[i];
  cin >> q;
  while (q--) {
    long long int sum = 0;
    cin >> old_val >> new_val;
    replace(a, a + n, old_val, new_val);
    cout << accumulate(a, a + n, sum) << endl;
  }
  return 0;
}
