#include <bits/stdc++.h>
using namespace std;
const int INF = 1e9;
const int MOD = 1e9 + 7;
int main() {
  int n;
  cin >> n;
  int long long a[100100];
  int long long ans = 0;
  for (int i = 0; i < (int)(n); i++) {
    int long long p;
    cin >> p;
    a[p]++;
    ans += p;
  }
  int q;
  cin >> q;
  for (int i = 0; i < (int)(q); i++) {
    int long long b, c;
    cin >> b >> c;
    ans = ans - a[b] * b + a[b] * c;
    a[c] += a[b];
    cout << ans << endl;
    a[b] = 0;
  }
}
