#include <bits/stdc++.h>
using namespace std;
long long int a[100001] = {0};
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  ;
  long long int n, t = 0;
  cin >> n;
  for (long long int i = 0; i < n; i++) {
    long long int x;
    cin >> x;
    t += x;
    a[x]++;
  }
  long long int q;
  cin >> q;
  for (long long int i = 0; i < q; i++) {
    long long int x, y;
    cin >> x >> y;
    a[y] += a[x];
    t += y * a[y] - x * a[x];
    a[x] = 0;
    cout << t << "\n";
  }
  return 0;
}
