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