#include <bits/stdc++.h>
using namespace std;
const long long M = 1e9 + 7;
const long long N = 1e6 + 10;
const long long IM = 1e15 + 37;
const long double PI = 3.1415926535897932384;
void PV(vector<long long> v) {
  for (long long i = 0; i < v.size(); i++) cout << v[i] << " ";
  cout << "\n";
}
void PVV(vector<pair<long long, long long> > v) {
  for (long long i = 0; i < v.size(); i++)
    cout << v[i].first << " " << v[i].second << "\n";
}
void PA(long long v[], long long n, long long x = 0) {
  for (long long i = x; i < n + x; i++) cout << v[i] << ' ';
  cout << "\n";
}
void IN(long long a[], long long n, long long x = 0) {
  for (long long i = x; i < n + x; i++) cin >> a[i];
}
inline void PP(long long n) { cout << n << " "; }
inline void PP(long long n, long long m) { cout << n << " " << m << "\n"; }
inline void PP(long long n, long long m, long long q) {
  cout << n << " " << m << " " << q << "\n";
}
inline void PP(long long n, long long m, long long q, long long u) {
  cout << n << " " << m << " " << q << " " << u << "\n";
}
inline void op() {}
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  long long i, j, x, y, u, l;
  {
    i = j = x = y = u = l = 0;
    long long n;
    cin >> n;
    map<long long, long long> m;
    for (i = 0; i < n; i++) {
      cin >> x;
      y += x;
      m[x]++;
    }
    cin >> x;
    while (x--) {
      cin >> u >> l;
      j = m[u];
      y += j * (l - u);
      m[l] = j;
      m[u] = 0;
      cout << (y) << "\n";
    }
  }
  return 0;
}
