#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, p, q, sum = 0;
  cin >> n;
  int a[n];
  for (int i = 0; i < n; i++) cin >> a[i];
  int k;
  cin >> k;
  while (k--) {
    sum = 0;
    cin >> p >> q;
    for (int i = 0; i < n; i++) {
      if (a[i] == p) a[i] = q;
    }
    for (int i = 0; i < n; i++) sum += a[i];
    cout << sum << endl;
  }
  return 0;
}
