#include <bits/stdc++.h>
using namespace std;
using vi = vector<int>;
using vvi = vector<vi>;
using pii = pair<int, int>;
using vpii = vector<pii>;
using int64 = long long;
const int inf = 2e9 + 7;
const char nwl = '\n';
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int n;
  cin >> n;
  int64 s = 0;
  map<int, int> mp;
  for (int i = 0; i < n; i++) {
    int x;
    cin >> x;
    mp[x]++;
    s += (int64)x;
  }
  int q;
  cin >> q;
  for (int i = 0; i < q; i++) {
    int x, y;
    cin >> x >> y;
    int k = mp[x];
    mp[y]++;
    int64 tmp = (int64)(y - x) * k;
    s += tmp;
    cout << s << nwl;
  }
  return 0;
}
