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