#include <bits/stdc++.h>
using namespace std;
const int mod = 1000000007;
void ash() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
}
int main() {
  ash();
  int n;
  cin >> n;
  vector<int> a;
  int sum = 0;
  unordered_map<int, int> m;
  for (int i = 0; i < n; i++) {
    int x;
    cin >> x;
    a.emplace_back(x);
    sum = sum + x;
    m[x]++;
  }
  int q;
  cin >> q;
  for (int i = 0; i < q; i++) {
    int x, y;
    cin >> x >> y;
    if (m.find(x) == m.end()) {
      cout << sum << "\n";
    } else {
      unordered_map<int, int>::iterator it = m.find(x);
      int e = it->second;
      sum = sum - ((it->first) * (it->second)) + ((y) * (it->second));
      cout << sum << "\n";
      m.erase(it);
      if (m.empty() != 1) {
        unordered_map<int, int>::iterator it1 = m.find(y);
        if (it1 != m.end()) {
          int r = it1->second;
          m.erase(it1);
          m[y] = e + r;
        } else {
          m[y] = e;
        }
      } else
        m[y] = e;
    }
  }
}
