#include <bits/stdc++.h>
using namespace std;
const long long mod = 1e9 + 7;
const long long inf = 1LL << 61;
int main() {
  long long n, q;
  cin >> n;
  long long a[n];
  map<long long, long long> mp;
  long long sum = 0;
  for (int i = 0; i < (int)(n); i++) {
    cin >> a[i];
    sum += a[i];
    mp[a[i]]++;
  }
  cin >> q;
  long long b[q], c[q];
  for (int i = 0; i < (int)(q); i++) {
    cin >> b[i] >> c[i];
  }
  for (int i = 0; i < (int)(q); i++) {
    sum += (c[i] - b[i]) * mp[b[i]];
    mp[c[i]] += mp[b[i]];
    cout << sum << endl;
  }
}
