#include <bits/stdc++.h>
using namespace std;
int main() {
  int N;
  cin >> N;
  map<int, int> m;
  long long sum = 0;
  for (int i = 0; i < N; i++) {
    int num;
    cin >> num;
    m[num]++;
    sum += num;
  }
  int Q;
  cin >> Q;
  for (int i = 0; i < Q; i++) {
    int b, c;
    cin >> b >> c;
    m[c] += m[b];
    sum = sum - (m[b] * b) + (m[b] * c);
    m[b] = 0;
    cout << sum << endl;
  }
}
