#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, q;
  cin >> n;
  vector<int> v;
  for (int i = 0; i < (n); i++) {
    int a;
    cin >> a;
    v.push_back(a);
  }
  cin >> q;
  vector<pair<int, int>> vv;
  for (int i = 0; i < (q); i++) {
    int a, b;
    cin >> a >> b;
    vv.push_back(pair<int, int>(a, b));
  }
  long long ans = 0;
  for (auto e : v) ans = ans + e;
  for (int i = 0; i < (q); i++) {
    int t = count(v.begin(), v.end(), vv[i].first);
    ans = ans + t * (vv[i].second - vv[i].first);
    cout << ans << endl;
    if (t == 0) continue;
    replace(v.begin(), v.end(), vv[i].first, vv[i].second);
  }
}
