#include <bits/stdc++.h>
using namespace std;
const int mod = 1000 * 1000 * 1000 + 7;
const int INF = 0x3f3f3f3f;
const long long LL_INF = 0x3f3f3f3f3f3f3f3f;
const double PI = 3.14159265359;
int dx[6] = {-1, -1, 0, 0, 1, 1};
int dy[6] = {-1, 0, -1, 1, 0, 1};
const int N = 2e5 + 5;
int a[N];
map<int, int> mp;
int main() {
  int n, q;
  cin >> n;
  long long sum = 0;
  for (int i = 0; i < n; ++i) {
    cin >> a[i];
    mp[a[i]] += 1;
    sum += a[i];
  }
  cin >> q;
  while (q--) {
    int b, c;
    cin >> b >> c;
    sum -= b * mp[b];
    sum += c * (mp[b]);
    mp[c] += mp[b];
    mp[b] = 0;
    cout << sum << endl;
  }
  return 0;
}
