#include <bits/stdc++.h>
using namespace std;
void printArray(vector<int> arr) {
  for (int a : arr) cout << a << " ";
  cout << '\n';
}
int a[100001];
long long s[100001];
int main() {
  std::ios_base::sync_with_stdio(false);
  int n, q;
  cin >> n;
  map<int, int> count;
  long long sum = 0;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    sum += a[i];
    if (count.find(a[i]) == count.end())
      count[a[i]] = 1;
    else
      count[a[i]]++;
  }
  cin >> q;
  for (int _ = 0; _ < q; _++) {
    int b, c, temp;
    cin >> b >> c;
    temp = count[b];
    count.erase(b);
    sum = sum - b * temp + c * temp;
    if (count.find(c) == count.end())
      count[c] = temp;
    else
      count[c] += temp;
    cout << sum << '\n';
  }
}
