#include <bits/stdc++.h>
const int mod = 1e9 + 7;
using namespace std;
void solve() {
  int n, q;
  cin >> n;
  long long sum = 0;
  vector<int> arr(100008, 0);
  for (int i = 0; i < n; ++i) {
    int x;
    cin >> x;
    arr[x]++;
    sum += x;
  }
  cin >> q;
  for (int i = 0; i < q; ++i) {
    int x, y;
    cin >> x >> y;
    long long t = arr[x], nw_sum = 0;
    arr[y]++;
    sum = (sum - (t * x));
    sum += (t * y);
    cout << (sum) << endl;
  }
}
int main() {
  ios_base ::sync_with_stdio(0);
  cin.tie(0);
  cout.precision(20);
  int t;
  solve();
  return 0;
}
