#include <bits/stdc++.h>
const int MOD = 1e9 + 7;
const int MOOD = 998244353;
using namespace std;
int coun[100001];
int main() {
  int n;
  cin >> n;
  for (int i = 0; i < n; i++) {
    int x;
    cin >> x;
    coun[x]++;
  }
  int q;
  cin >> q;
  for (int i = 0; i < q; i++) {
    int b, c;
    cin >> b >> c;
    coun[c] += coun[b];
    coun[b] = 0;
    long long ans = 0;
    for (int j = 1; j <= 100000; j++) {
      ans += coun[j] * j;
    }
    cout << ans << endl;
  }
}
