#define _CRT_SECURE_NO_DEPRECATE
#include <stdio.h>
#include <vector>
#include <algorithm>
#include <stdlib.h>
#include <ctime>
#include <set>
#include <map>
#include <queue>
#include <string>
#include <math.h>
#include <queue>
#include <memory.h>
#include <iostream>
#include <fstream>
#include <stack>
#include <complex>
#include <list>

using namespace std;

void ASS(bool bb)
{
    if (!bb)
    {
        ++*(int*)0;
    }
}

#define FOR(i, x) for (int i = 0; i < (int)(x); ++i)
#define CL(x) memset(x, 0, sizeof(x))
#define CLX(x, y) memset(x, y, sizeof(x))

#pragma comment(linker, "/STACK:106777216") 

typedef vector<int> vi;

typedef long long LL;

const int K = 200;
const int QK = 400;

struct M {
    int x;
    int* p;
};

vector<M> mem;
LL TotalSum;

struct Revertable {
    Revertable()
        : x(0)
    {
    }
    int Get() const {
        return x;
    }
    void Set(int xx) {
        M m;
        m.x = x;
        m.p = &x;
        mem.push_back(m);
        x = xx;
    }
    void UnRevertableSet(int xx) {
        x = xx;
    }
private:
    int x;
};

struct TBackup {
    size_t pos;
    LL sum;
    void Init() {
        pos = mem.size();
        sum = TotalSum;
    }
    void BackUp() {
        while (mem.size() > pos) {
            *mem.back().p = mem.back().x;
            mem.pop_back();
        }
        TotalSum = sum;
    }
};

vector<Revertable> ar;
vector<Revertable> cnt;

vi values;

struct Q {
    int update, x, y, id;
};

void Add(int x) {
    if (cnt[x].Get() == 0)
        TotalSum += values[x];
    cnt[x].Set(cnt[x].Get() + 1);
}

void Del(int x) {
    if (cnt[x].Get() == 1)
        TotalSum -= values[x];
    cnt[x].Set(cnt[x].Get() - 1);
}

vector<LL> Solve(vi a, vector<Q> q) {
    const int n = (int)a.size();
    const int qn = (int)q.size();

    values = a;
    FOR(i, qn) {
        q[i].id = i;
        if (q[i].update)
            values.push_back(q[i].y);
    }

    sort(values.begin(), values.end());
    values.resize(unique(values.begin(), values.end()) - values.begin());

    FOR(i, n)
        a[i] = (int)(lower_bound(values.begin(), values.end(), a[i]) - values.begin());

    FOR(i, qn)
        if (q[i].update)
            q[i].y = (int)(lower_bound(values.begin(), values.end(), q[i].y) - values.begin());

    ar.resize(n);
    FOR(i, n)
        ar[i].UnRevertableSet(a[i]);
    cnt.resize(values.size());

    vector<LL> ans(qn);
    const int c = n / K + (n % K != 0);
    for (int qL = 0; qL < qn; qL += QK) {
        int qR = min(qL + QK, qn);
        vector< vector< vector<Q> > > qq(c + 2, vector< vector<Q> >(c + 2));
        vector<Q> qu;
        qu.reserve(QK);
        for (int i = qL; i < qR; ++i)
            if (q[i].update)
                qu.push_back(q[i]);
            else
                qq[q[i].x / K + 1][q[i].y / K].push_back(q[i]);

        for (int L = 1, Lk = K; L <= c; ++L, Lk += K) {
            TBackup bL;
            bL.Init();
            for (int R = L - 1, Rk = Lk - K; R <= c; ++R, Rk += K) {
                TBackup bR;
                bR.Init();
                size_t qpos = 0;
                const vector<Q>& z = qq[L][R];
                FOR(i, z.size()) {
                    const Q& curQ = z[i];
                    while (qpos < qu.size() && qu[qpos].id < curQ.id) {
                        const Q& u = qu[qpos];
                        if (Lk <= u.x && u.x < Rk)
                            Del(ar[u.x].Get());
                        ar[u.x].Set(u.y);
                        if (Lk <= u.x && u.x < Rk)
                            Add(ar[u.x].Get());
                        ++qpos;
                    }
                    TBackup bQuery;
                    bQuery.Init();
                    if (R == L - 1) {
                        for (int j = curQ.x; j < curQ.y; ++j) {
                            Add(ar[j].Get());
                        }
                    } else {
                        for (int j = curQ.x; j < Lk; ++j)
                            Add(ar[j].Get());
                        for (int j = Rk; j < curQ.y; ++j)
                            Add(ar[j].Get());
                    }
                    ans[curQ.id] = TotalSum;
                    bQuery.BackUp();
                }
                bR.BackUp();
                if (R >= L) {
                    int Rnext = min(n, Rk + K);
                    for (int i = Rk; i < Rnext; ++i)
                        Add(ar[i].Get());
                }
            }
            bL.BackUp();
        }
        for (int i = qL; i < qR; ++i)
            if (q[i].update)
                ar[q[i].x].UnRevertableSet(q[i].y);
    }
    return ans;
}

vector<LL> SolveV(vi a, vector<Q> q) {
    vector<LL> ans(q.size(), 0);
    FOR(i, q.size()) {
        if (q[i].update)
            a[q[i].x] = q[i].y;
        else {
            map<int, int> m;
            for (int j = q[i].x; j < q[i].y; ++j) {
                int &t = m[a[j]];
                if (!t) {
                    t = 1;
                    ans[i] += a[j];
                }
            }
        }
    }
    return ans;
}

int read() {
    int x;
    scanf("%d", &x);
    return x;
}

void InputAndSolve() {
    int n = read();
    vi a(n);
    FOR(i, n)
        a[i] = read();

    int qn = read();
    vector<Q> q(qn);

    FOR(i, qn) {
        static char s[16];
        scanf("%s%d%d", s, &q[i].x, &q[i].y);
        q[i].x--;
        q[i].id = i;
        q[i].update = s[0] == 'U';
    }

    vector<LL> ans = SolveV(a, q);
    FOR(i, qn)
        if (!q[i].update) {
//            cout << ans[i] << "\n";
            printf("%lld\n", ans[i]);
        }
}

int main()
{
    InputAndSolve();

    /*
    FOR(qqq, 1000) {
        int n = rand() % 10 + 10;
        vi a(n);
        FOR(i, n)
            a[i] = rand() % (n / 2);
        int qn = n * 2;
        vector<Q> q(qn);
        FOR(i, qn) {
            q[i].id = i;
            if (rand() & 1) {
                q[i].update = 1;
                q[i].x = rand() % n;
                q[i].y = rand() % (n / 2);
            } else {
                q[i].update = 0;
                q[i].x = rand() % n;
                q[i].y = rand() % n;
                if (q[i].x > q[i].y)
                    swap(q[i].x, q[i].y);
                q[i].y++;
            }
        }
        vector<LL> v0 = Solve(a, q);
        vector<LL> v1 = SolveV(a, q);
        if (v0 != v1) {
            cout << "gg" << endl;
        }
    }
    */

    return 0;
}
