#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--) {
    long long int sum = 0;
    int x, y;
    cin >> x >> y;
    for (int i = 0; i < n; i++) {
      if (x == a[i]) a[i] = y;
      sum += a[i];
    }
    cout << sum << endl;
  }
}
