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