#include <iostream>
#include <algorithm>
#include <type_traits>
#include <iterator>
#include <vector>
#include <cstdint>
using namespace std;

template <typename T, typename Iter>
constexpr Iter bsearch(Iter first, Iter last, const T &v) {
    static_assert(
            std::is_same_v<
                typename iterator_traits<Iter>::iterator_category,
                random_access_iterator_tag
            >, ""
    );

    auto dist = distance(first, last);
    if (dist == 0)return last;

    Iter part = first, found = last;
    do {
        dist /= 2;
        auto bound = part + dist;

        if (*bound == v) {
            found = bound;
            break;
        }

        if (*bound < v)part = bound;
    } while (dist);
    if (found == last)return last;

    while (first < found && *(found - 1) == v)--found;
    return found;
}

int main() {
    uint32_t n, q;
    uint64_t s = 0;
    vector<uint32_t> a;

    cin >> n;
    a.resize(n);
    for (auto &e : a) {
        cin >> e;
        s += e;
    }
    cin >> q;

    sort(a.begin(), a.end());
    uint32_t b, c;
    while (q--) {
        cin >> b >> c;

        for (auto first = bsearch(a.begin(), a.end(), b); first != a.end() && *first == b; ++first) {
            *first = c;
            s -= b;
            s += c;
        }

        cout << s << endl;
    }
}

