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