#include <bits/stdc++.h>
using namespace std;
const long long M = 1e9 + 7;
const int iinf = 1 << 29;
const long long llinf = 1ll << 60;
const double PI = 3.14159265;
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
long long mrand(long long B) { return (unsigned long long)rng() % B; }
void work() {
  int n;
  cin >> n;
  vector<int> v(1e5 + 1, 0);
  long long s = 0;
  for (int i = 0; i < n; ++i) {
    int a;
    cin >> a;
    ++v[a];
    s += a;
  }
  int q;
  cin >> q;
  while (q--) {
    int b, c;
    cin >> b >> c;
    s -= v[b] * b;
    s += v[b] * c;
    v[c] += v[b];
    v[b] = 0;
    cout << s << "\n";
  }
}
int main() {
  ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  work();
  return 0;
}
