#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  ;
  int n;
  cin >> n;
  map<int, int> m;
  long long s = 0;
  int a[n];
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    m[a[i]]++;
    s += a[i];
  }
  int t;
  cin >> t;
  while (t--) {
    int a, b;
    cin >> a >> b;
    int x = m[a];
    s -= x * a;
    s += x * b;
    m[a] -= x;
    m[b] += x;
    cout << s << "\n";
  }
}
