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