#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
using namespace std;
const int INF = 1e9 + 5;
const int MOD = 1e9 + 7;
const long long int inf = 2e18 + 11;
double pi = 2 * acos(0.0);
void solve() {
  int n;
  cin >> n;
  int a[n];
  long long int s = 0;
  map<int, int> m;
  for (int i = 0; i < n; ++i) cin >> a[i], s += a[i], m[a[i]]++;
  int q, b, c;
  cin >> q;
  while (q--) {
    cin >> b >> c;
    s -= (m[b] * b);
    s += (m[b] * c);
    m[c] += m[b];
    m[b] = 0;
    cout << s << '\n';
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  ;
  int t = 1;
  while (t--) solve();
  return 0;
}
