#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  int a[n];
  int r[100001] = {0};
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    r[a[i]]++;
  }
  long long int sum = accumulate(a, a + n, 0);
  int q;
  cin >> q;
  for (int i = 0; i < q; i++) {
    int a, b;
    cin >> a >> b;
    sum = sum - (long long int)(a * r[a]);
    sum += (long long int)(r[a] * b);
    r[b] += r[a];
    r[a] = 0;
    cout << sum << "\n";
  }
}
