#include <bits/stdc++.h>
using namespace std;
const int MOD1 = 1e9 + 7;
const int MOD2 = 998244353;
const long long INF = 2 * 1e18;
const long double PI = 3.14159265358979323846;
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  long long n, q, sum = 0;
  map<long long, long long> m;
  set<long long> s;
  cin >> n;
  for (long long i = 0; i < n; i++) {
    long long a;
    cin >> a;
    m[a]++;
    s.insert(a);
    sum += a;
  }
  cin >> q;
  while (q--) {
    long long b, c;
    cin >> b >> c;
    if (s.count(b)) {
      s.erase(b), s.insert(c);
      sum += m[b] * (c - b);
      m[c] += m[b];
    }
    cout << sum << "\n";
  }
}
