#include <bits/stdc++.h>
using namespace std;
const double PI = 3.14159265358979323846;
const double EPS = 1e-9;
const long long INF = 10e17;
double equal(double a, double b) { return fabs(a - b) < DBL_EPSILON; }
std::istream &operator>>(std::istream &in, set<int> &o) {
  int a;
  in >> a;
  o.insert(a);
  return in;
}
std::istream &operator>>(std::istream &in, queue<int> &o) {
  long long a;
  in >> a;
  o.push(a);
  return in;
}
bool contain(set<int> &s, int a) { return s.find(a) != s.end(); }
int main() {
  int n;
  cin >> n;
  vector<long long> as(n);
  for (int i = 0; i < (n); ++i) cin >> as[i];
  long long sum = accumulate(as.begin(), as.end(), 0ll);
  map<long long, int> m;
  for (long long a : as) m[a]++;
  int q;
  cin >> q;
  for (int _ = 0; _ < (q); ++_) {
    int b, c;
    cin >> b >> c;
    int from = m[b];
    long long sub = from * b;
    sum -= sub;
    long long add = from * c;
    sum += add;
    m.erase(b);
    m[c] += from;
    cout << sum << endl;
  }
}
