#include <bits/stdc++.h>
using namespace std;
const long double PI = 3.14159265358979323846264338327950;
const int mod = 1000000007;
int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  int n;
  cin >> n;
  vector<int> arr(n);
  map<int, int> m;
  unsigned long long int sum = 0ULL;
  for (int i = 0; i < n; i++) {
    cin >> arr[i];
    m[arr[i]]++;
    sum += arr[i];
  }
  int q;
  cin >> q;
  while (q--) {
    int a, b;
    cin >> a >> b;
    int freq = m[a];
    sum = sum - freq * a + freq * b;
    m.erase(a);
    m[b] += freq;
    cout << sum << endl;
  }
}
