#include <bits/stdc++.h>
using namespace std;
void solve() {
  int n;
  cin >> n;
  vector<int> a(n);
  int num[100009];
  for (int i = 0; i < 100009; i++) {
    num[i] = 0;
  }
  int sum = 0;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    num[a[i]]++;
    sum += a[i];
  }
  int q;
  cin >> q;
  for (int i = 0; i < q; i++) {
    int a, b;
    cin >> a >> b;
    num[b] += num[a];
    sum = sum + num[a] * (b - a);
    num[a] = 0;
    cout << sum << endl;
    ;
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  solve();
  return 0;
}
