#include <bits/stdc++.h>
using namespace std;
int main() {
  long long int n;
  cin >> n;
  vector<int> a(n, 0);
  map<int, int> m;
  long long int sum = 0;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    sum += a[i];
    m[a[i]]++;
  }
  int q;
  cin >> q;
  while (q--) {
    int x, y;
    cin >> x >> y;
    sum += ((m[y]) * y) - (m[x] * x);
    m[y] = m[x] + m[y];
    m[x] = 0;
    cout << sum << endl;
  }
}
