#include <bits/stdc++.h>
using namespace std;
void solve() {
  int n;
  cin >> n;
  vector<int> v(n);
  map<int, int> mp;
  long long sum = 0;
  for (int i = 0; i < n; i++) {
    cin >> v[i];
    mp[v[i]]++;
    sum += v[i];
  }
  int q;
  cin >> q;
  for (int i = 0; i < q; i++) {
    int a, b;
    cin >> a >> b;
    sum = (sum - mp[a] * a) + mp[a] * b;
    mp[b] += mp[a];
    mp[a] = 0;
    cout << sum << endl;
  }
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  solve();
}
