#include <bits/stdc++.h>
double arr[1007];
using namespace std;
int main() {
  long long int t, item, temp, a, m, x, y, z;
  long long int x1, x2, y1, y2;
  vector<long long int> v;
  string s1, s2, s3;
  stack<string> ba;
  stack<string> fo;
  vector<long long int> v1;
  vector<long long int> v2;
  map<long long int, long long int> mp1;
  map<long long int, long long int> mp2;
  long long int r, g, b;
  long long int n;
  cin >> n;
  long long int ans = 0;
  for (int i = 1; i <= n; i++) {
    cin >> item;
    ans += item;
    mp1[item]++;
  }
  cin >> t;
  while (t--) {
    cin >> a >> b;
    temp = mp1[a];
    mp1[b] += temp;
    ans += temp * b - a * temp;
    cout << ans << endl;
  }
  return 0;
}
