#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;
int main() {
  int n;
  cin >> n;
  vector<int> a(100005);
  int tot = 0;
  for (int i = 0; i < (n); ++i) {
    int k;
    cin >> k;
    a[k]++;
    tot += k;
  }
  vector<int> ans;
  int q;
  cin >> q;
  for (int i = 0; i < (q); ++i) {
    int b, c;
    cin >> b >> c;
    int t = a[b];
    tot -= t * b;
    tot += t * c;
    ans.push_back(tot);
    a[b] = 0;
    a[c] += t;
  }
  int s = ans.size();
  for (int i = 0; i < (s); ++i) {
    cout << ans[i] << endl;
  }
}
