#include <bits/stdc++.h>
using namespace std;
const int INF = 1e9;
const long long mod = 1e9 + 7;
const int dx[] = {1, 0, -1, 0}, dy[] = {0, 1, 0, -1};
int main() {
  int n;
  cin >> n;
  vector<int> a(n);
  map<int, int> mp;
  int 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 s, t;
    cin >> s >> t;
    sum += (t - s) * mp[s];
    cout << sum << endl;
    mp[t] += mp[s];
    mp[s] = 0;
  }
  return 0;
}
