#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 5;
int frr[N];
int main() {
  int n;
  cin >> n;
  long long sum = 0;
  for (int i = 0; i < n; i++) {
    int a;
    cin >> a;
    frr[a]++;
    sum += a;
  }
  int q;
  cin >> q;
  while (q--) {
    int a, b;
    cin >> a >> b;
    int k = frr[a];
    sum -= (k * a);
    frr[b] += k;
    sum += (k * b);
    cout << sum << endl;
  }
}
