#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 10;
int n, q;
int a[N];
map<int, int> mp;
long long sum = 0;
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cin >> n;
  for (int i = 1; i <= n; i++) cin >> a[i], sum += a[i], mp[a[i]]++;
  cin >> q;
  for (int i = 1; i <= q; i++) {
    int x, y;
    cin >> x >> y;
    sum += (y - x) * mp[x];
    mp[y] = mp[x];
    mp[x] = 0;
    cout << sum << '\n';
  }
}
