#include <bits/stdc++.h>
using namespace std;
const int mxN = 2e5;
int a[mxN];
int sum(vector<long long> v, long long n) {
  long long s = 0;
  for (long long i = 0; i < n; ++i) s += v[i];
  return s;
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  long long n;
  cin >> n;
  vector<long long> v(n);
  for (auto &x : v) cin >> x;
  long long t;
  cin >> t;
  long long s = sum(v, n);
  map<long long, long long> m;
  for (auto x : v)
    if (m.find(x) != m.end())
      m[x] += 1;
    else
      m[x] = 1;
  while (t--) {
    long long b, c;
    cin >> b >> c;
    if (m.find(c) != m.end())
      m[c] += m[b];
    else
      m[c] = m[b];
    s += ((c - b) * m[b]);
    cout << s << "\n";
    m[b] = 0;
  }
  return 0;
}
