#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() {
  long long n;
  cin >> n;
  map<long long, long long> mp;
  vector<long long> array(n);
  for (int i = 0; i < (n); ++i) {
    long long a;
    cin >> a;
    array[i] = a;
    mp[a]++;
  }
  long long q;
  cin >> q;
  for (int i = 0; i < (q); ++i) {
    long long a, b, sum = 0;
    cin >> a >> b;
    mp[b] += mp[a];
    mp[a] = 0;
    for (int j = 0; j < (100001); ++j) {
      if (j == a) continue;
      sum += j * mp[j];
    }
    cout << sum << endl;
  }
  return 0;
}
