#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
const long long INF = 1e17 + 7;
const long long MOD = 1e9 + 7;
const int SIZE = 1e6 + 10;
const double PI = acos(-1);
using namespace std;
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n;
  cin >> n;
  long long sum = 0;
  map<int, int> mp;
  for (int i = 0; i < n; i++) {
    int x;
    cin >> x;
    mp[x]++;
    sum += x;
  }
  int q;
  cin >> q;
  for (int i = 0; i < q; i++) {
    int b, c;
    cin >> b >> c;
    long long sum_temp = sum - (b * mp[b]) + (c * mp[b]);
    mp[c] += mp[b];
    mp[b] = 0;
    cout << sum_temp << endl;
    sum = sum_temp;
  }
  return 0;
}
