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