#include <bits/stdc++.h>
using namespace std;
const long long N = 1e3 + 7;
const long long mod = 1e9 + 7;
void solve() {
  int n;
  cin >> n;
  vector<int> a(n + 1);
  int sum = 0;
  map<int, int> mp;
  for (int i = 1; i <= n; ++i) {
    cin >> a[i];
    sum += a[i];
    ++mp[a[i]];
  }
  int q, b, c;
  cin >> q;
  while (q--) {
    cin >> b >> c;
    sum += (c - b) * mp[b];
    mp[c] += mp[b];
    mp[b] = 0;
    cout << sum << "\n";
  }
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int tt = 1;
  while (tt--) {
    solve();
  }
}
