#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ii = pair<int, int>;
using vi = vector<int>;
using vll = vector<ll>;
using vii = vector<ii>;
using vvi = vector<vi>;
using vvll = vector<vll>;
using vs = vector<string>;
const int INF = 1 << 30;
const int MAX_N = 100000 + 5;
const int MAX_L = 20;
const ll MOD = 1e9 + 7;
const int xd[4] = {1, 0, -1, 0}, yd[4] = {0, 1, 0, -1};
void dbg_out() { cout << endl; }
void __print(int x) { cout << x; }
void __print(long x) { cout << x; }
void __print(long long x) { cout << x; }
void __print(unsigned x) { cout << x; }
void __print(unsigned long x) { cout << x; }
void __print(unsigned long long x) { cout << x; }
void __print(float x) { cout << x; }
void __print(double x) { cout << x; }
void __print(long double x) { cout << x; }
void __print(char x) { cout << '\'' << x << '\''; }
void __print(const char *x) { cout << '\"' << x << '\"'; }
void __print(const string &x) { cout << '\"' << x << '\"'; }
void __print(bool x) { cout << (x ? "true" : "false"); }
template <typename T, typename V>
void __print(const pair<T, V> &x) {
  cout << '{';
  __print(x.first);
  cout << ',';
  __print(x.second);
  cout << '}';
}
template <typename T>
void __print(const T &x) {
  int f = 0;
  cout << '{';
  for (auto &i : x) cout << (f++ ? "," : ""), __print(i);
  cout << "}";
}
void _print() { cout << "]\n"; }
template <typename T, typename... V>
void _print(T t, V... v) {
  __print(t);
  if (sizeof...(v)) cout << ", ";
  _print(v...);
}
void setIn(string s) { freopen(s.c_str(), "r", stdin); }
void setOut(string s) { freopen(s.c_str(), "w", stdout); }
void unsyncIO() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
}
void setIO(string s = "") {
  unsyncIO();
  if ((int)((s).size())) {
    setIn(s + ".in"), setOut(s + ".out");
  }
}
template <typename T>
void output_vector(const vector<T> &v, int start = -1, int end = -1) {
  if (start < 0) start = 0;
  if (end < 0) end = int(v.size());
  for (int i = start; i < end; i++) cout << v[i] << " ";
  cout << endl;
}
template <typename T>
struct Point {
  T x, y;
  Point(T _x, T _y) : x(_x), y(_y) {}
  friend ostream &operator<<(ostream &os, const Point &p) {
    return os << "(" << p.x << ", " << p.y << ")";
  }
};
int bit(int x) { return 31 - __builtin_clz(x); }
int cdiv(int a, int b) { return a / b + !(a < 0 || a % b == 0); }
ll qexp(ll A, ll B, ll M) {
  if (B == 0) return 1;
  ll half = qexp(A, B / 2, M) % M;
  half *= half;
  half %= M;
  if (B % 2 == 1) half *= A;
  return half % M;
}
struct Compare {
  bool operator()(pair<int, int> const &a, pair<int, int> const &b) {
    if (a.first != b.first) {
      return a.first < b.first;
    }
    return a.second > b.second;
  }
};
void run_case() {
  int n;
  cin >> n;
  map<int, int> freq;
  ll total = 0;
  for (int i = (0); i < (n); ++i) {
    int elem;
    cin >> elem;
    ++freq[elem];
    total += elem;
  }
  int Q;
  cin >> Q;
  for (int i = (0); i < (Q); ++i) {
    int prev, next;
    cin >> prev >> next;
    int count = freq[prev];
    total -= count * prev;
    total += count * next;
    freq[prev] = 0;
    freq[next] += count;
    cout << total << endl;
  }
}
int main() {
  setIO();
  int tests = 1;
  while (tests--) {
    run_case();
    ;
  }
}
