#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
const int mod = 1e9 + 7;
const ll infll = (1LL << 62) - 1;
const int inf = (1 << 30) - 1;
void YesNo(bool j) {
  cout << (j ? "Yes" : "No") << endl;
  return;
}
void yesno(bool j) {
  cout << (j ? "yes" : "no") << endl;
  return;
}
template <class Head>
void pt(Head&& head) {
  cout << head << endl;
  return;
}
int d[200001];
int main() {
  int n;
  cin >> n;
  vector<int> a(n);
  for (int i = 0; i < (n); ++i) cin >> a[i];
  int q;
  cin >> q;
  int res = 0;
  for (int i = 0; i < (n); ++i) {
    res += a[i];
    d[a[i]]++;
  }
  for (int i = 0; i < (q); ++i) {
    int b, c;
    cin >> b >> c;
    res += (c - b) * d[b];
    d[c] += d[b];
    d[b] = 0;
    pt(res);
  }
  return 0;
}
