#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  vector<vector<int>> a(100000, vector<int>(1));
  long long ans = 0;
  for (int i = 0; i < n; i++) {
    int x;
    cin >> x;
    a.at(x).at(0)++;
    ans += x;
  }
  int q;
  cin >> q;
  while (q > 0) {
    int b, c;
    cin >> b >> c;
    int d = a.at(b).at(0);
    a.at(c).at(0) += a.at(b).at(0);
    a.at(b).at(0) = 0;
    ans -= b * d;
    ans += c * d;
    cout << ans << endl;
    q--;
  }
}
