#include <bits/stdc++.h>
using namespace std;
const int I_INF = 1001001001;
const long long LL_INF = 1001001001001001001;
const long double EPS = 0.001;
int main() {
  int N, Q;
  cin >> N;
  map<long long, long long> a;
  for (int i = 0; i < (int)(N); i++) {
    long long n = 0;
    cin >> n;
    a[n]++;
  }
  cin >> Q;
  vector<long long> ans;
  for (int i = 0; i < (int)(Q); i++) {
    long long b, c;
    cin >> b >> c;
    if (a.count(b)) {
      long long v = a[b];
      a.erase(b);
      a[c] += v;
    }
    long long s = 0;
    for (const auto [key, value] : a) s += key * value;
    ans.push_back(s);
  }
  for (const auto n : ans) cout << n << endl;
}
