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