#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1000000007;
const double EPS = 1e-10;
const int MAX = 200000;
int main() {
  long long n, q, k;
  cin >> n;
  vector<long long> a(n, 0);
  map<long long, vector<long long>> m;
  long long sum = 0;
  for (int i = 0; i < n; i++) {
    cin >> k;
    auto itr = m.find(k);
    if (itr != m.end()) {
      (itr->second).push_back(i);
    } else {
      vector<long long> v;
      v.push_back(i);
      m.insert(make_pair(k, v));
    }
    sum += k;
  }
  cin >> q;
  for (int i = 0; i < q; i++) {
    long long b, c;
    cin >> b >> c;
    sum += m[b].size() * (c - b);
    cout << sum << endl;
    for (int j = 0; j < m[b].size(); j++) {
      m[c].push_back(m[b][j]);
    }
    m[b].clear();
  }
  return 0;
}
