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