#include <bits/stdc++.h>
using namespace std;
void fast() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
}
void solve() {
  int n;
  cin >> n;
  int arr[n];
  for (int i = 0; i < n; i++) cin >> arr[i];
  int q;
  cin >> q;
  unordered_map<int, int> m;
  unsigned long long int sum = 0;
  for (int i = 0; i < n; i++) {
    m[arr[i]]++;
    sum += arr[i];
  }
  for (int i = 0; i < q; i++) {
    int b, c;
    cin >> b >> c;
    sum = sum - (b * m[b]) + (c * m[b]);
    cout << sum << endl;
    m[c] = m[c] + m[b];
    m.erase(b);
  }
}
int main() {
  fast();
  solve();
  return 0;
}
