#include <bits/stdc++.h>
using namespace std;
int tc = 1;
vector<string> split(const string &s, char c) {
  vector<string> v;
  stringstream ss(s);
  string x;
  while (getline(ss, x, c)) v.emplace_back(x);
  return move(v);
}
void err(vector<string>::iterator it) {}
template <typename T, typename... Args>
void err(vector<string>::iterator it, T a, Args... args) {
  cout << it->substr((*it)[0] == ' ', it->length()) << " = " << a << " ";
  err(++it, args...);
}
const int M = 1e9 + 7;
const long long Inf = (long long)2e18 + 5;
const int N = 2e5 + 5;
long long vis[N], res[N];
int solve() {
  int n;
  int sum = 0;
  cin >> n;
  int a[n];
  map<int, int> m;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    sum += a[i];
    m[a[i]]++;
  }
  int q;
  cin >> q;
  while (q--) {
    int a, b;
    cin >> a >> b;
    if (m[a]) {
      int x = m[a];
      sum -= (a * m[a]);
      m[a] = 0;
      m[b] += x;
      sum += (b * x);
    }
    cout << sum << endl;
  }
  return 0;
}
int main() {
  int test = 1;
  while (test--) solve();
  return 0;
}
