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