#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int n, q;
  cin >> n;
  vector<int> a;
  unordered_map<int, int> m;
  for (int e = 0; e < n; e++) {
    int y;
    cin >> y;
    a.push_back(y);
  };
  vector<int> b, c;
  cin >> q;
  for (int i = 0; i < q; i++) {
    int x, y;
    cin >> x >> y;
    b.push_back(x);
    c.push_back(y);
  }
  for (int i = 0; i < n; i++) {
    m[a[i]]++;
  }
  long long sum = accumulate(a.begin(), a.end(), 0);
  for (int i = 0; i < q; i++) {
    int cx = 0;
    if (m[b[i]]) {
      cx = m[b[i]];
      m[b[i]] = 0;
    } else {
      cout << sum << endl;
      continue;
    }
    m[c[i]] += cx;
    sum = sum + (c[i] - b[i]) * cx;
    cout << sum << endl;
  }
}
