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