#include <bits/stdc++.h>
using namespace std;
const long long int MOD = 1e9 + 7;
const long long int maxn = 2e5 + 5;
void solve() {
  int n;
  cin >> n;
  map<int, int> mp;
  long long int sum = 0;
  for (int i = 0; i < n; i++) {
    int a;
    cin >> a;
    mp[a]++;
  }
  for (auto x : mp) {
    sum += (x.first) * (x.second);
  }
  int q;
  cin >> q;
  int a, b;
  while (q--) {
    cin >> a >> b;
    sum -= mp[a] * a;
    sum += mp[a] * b;
    mp[b] += mp[a];
    mp[a] = 0;
    cout << sum << '\n';
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  solve();
  cerr << endl
       << "[ Time : " << (float)clock() / CLOCKS_PER_SEC << " secs ]" << endl;
}
