#include <bits/stdc++.h>
using namespace std;
void solve() {
  int n;
  cin >> n;
  map<int, int> mp;
  long long sum = 0;
  while (n--) {
    int x;
    cin >> x;
    mp[x]++;
    sum += x;
  }
  int q;
  cin >> q;
  while (q--) {
    int x, y;
    cin >> x >> y;
    sum += mp[x] * y;
    sum -= mp[x] * x;
    mp[y] += mp[x];
    mp[x] = 0;
    cout << sum << "\n";
  }
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(NULL);
  cout << fixed;
  cout << setprecision(0);
  solve();
  return 0;
}
