#include using namespace std; using ll = long long; #define rep(i, s, t) for (int i = (int)(s); i < (int)(t); ++i) #define revrep(i, t, s) for (int i = (int)(t)-1; i >= (int)(s); --i) #define all(x) begin(x), end(x) template bool chmax(T& a, const T& b) { return a < b ? (a = b, 1) : 0; } template bool chmin(T& a, const T& b) { return a > b ? (a = b, 1) : 0; } class Mo { public: Mo() = default; explicit Mo(int n) : n(n), cnt(0) {} void query(int l, int r) { queries.emplace_back(cnt++, l, r); } template void run(ExL exl, ShL shl, ExR exr, ShR shr, Out out) { int s = sqrt(n); std::sort(queries.begin(), queries.end(), [&](const auto& a, const auto& b) { if (a.l / s != b.l / s) return a.l < b.l; return a.r < b.r; }); int curL = 0, curR = 0; for (auto [id, l, r] : queries) { while (curL > l) exl(--curL); while (curR < r) exr(curR++); while (curL < l) shl(curL++); while (curR > r) shr(--curR); out(id); } } private: struct Query { int id, l, r; Query(int id, int l, int r) : id(id), l(l), r(r) {} }; int n, cnt; std::vector queries; }; int main() { ios_base::sync_with_stdio(false); cin.tie(nullptr); cout << fixed << setprecision(15); int N, M, Q; cin >> N >> M >> Q; vector P(N); vector ac(N); rep(i, 0, N) { int p; string s; cin >> p >> s; --p; P[i] = p; ac[i] = s == "AC"; } Mo mo(N); vector ans_correct(Q), ans_penalty(Q); rep(_, 0, Q) { int l, r; cin >> l >> r; --l; mo.query(l, r); } vector>> sub(M); vector ac_cnt(M); int correct = 0, penalty = 0; auto exl = [&](int i) { int p = P[i]; if (ac_cnt[p] && !sub[p].empty() && !sub[p].front().first) { penalty -= sub[p].front().second; } if (ac[i]) { if (ac_cnt[p] == 0) { ++correct; } ++ac_cnt[p]; } if (!sub[p].empty() && sub[p].front().first == ac[i]) { sub[p].front().second++; } else { sub[p].push_front({ac[i], 1}); } if (ac_cnt[p] && !sub[p].empty() && !sub[p].front().first) { penalty += sub[p].front().second; } }; auto shl = [&](int i) { int p = P[i]; if (!sub[p].front().first) { penalty -= sub[p].front().second; } sub[p].front().second--; if (sub[p].front().second == 0) sub[p].pop_front(); if (ac[i]) { --ac_cnt[p]; if (ac_cnt[p] == 0) { --correct; } } if (!sub[p].empty() && !sub[p].front().first) { penalty += sub[p].front().second; } }; auto exr = [&](int i) { int p = P[i]; if (ac[i]) { if (ac_cnt[p] == 0) { ++correct; } ++ac_cnt[p]; if (sub[p].size() == 1 && !sub[p].front().first) { penalty += sub[p].front().second; } } if (!sub[p].empty() && sub[p].back().first == ac[i]) { sub[p].back().second++; } else { sub[p].push_back({ac[i], 1}); } }; auto shr = [&](int i) { int p = P[i]; sub[p].back().second--; if (sub[p].back().second == 0) sub[p].pop_back(); if (ac[i]) { --ac_cnt[p]; if (ac_cnt[p] == 0) { --correct; if (!sub[p].empty() && !sub[p].front().first) { penalty -= sub[p].front().second; } } } }; auto out = [&](int id) { ans_correct[id] = correct; ans_penalty[id] = penalty; }; mo.run(exl, shl, exr, shr, out); rep(i, 0, Q) { cout << ans_correct[i] << " " << ans_penalty[i] << "\n"; } }