#include <bits/stdc++.h>
using namespace std;
const int MOD = 1000000007;
const double pi = 3.141592653589793;
int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int n;
  cin >> n;
  vector<int64_t> a(n);
  map<int, int> p;
  int64_t sum = 0;
  for (int i = 0; i < (int)(n); i++) {
    cin >> a[i];
    sum += a[i];
    p[a[i]]++;
  }
  int q;
  cin >> q;
  for (int i = 0; i < (int)(q); i++) {
    int64_t b, c;
    cin >> b >> c;
    int64_t bcount = p[b];
    sum -= b * bcount;
    sum += c * bcount;
    p[c] += bcount;
    cout << sum << endl;
  }
}
