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