#include <bits/stdc++.h>
using namespace std;
using Graph = vector<vector<int>>;
using ll = long long;
int main() {
  int n;
  cin >> n;
  vector<ll> temp(100000, 0);
  int ans = 0;
  for (int i = 0; i < (int)(n); i++) {
    int a;
    cin >> a;
    temp[a]++;
    ans += a;
  }
  int q;
  cin >> q;
  for (int i = 0; i < (int)(q); i++) {
    int b, c;
    cin >> b >> c;
    ans -= temp[b] * b;
    ans += temp[c] * c;
    temp[c] += temp[b];
    temp[b] = 0;
    cout << ans << endl;
  }
}
