#include using namespace std; const int nax = 1e6 + 5; int in[nax], score[nax]; vector inv[nax]; int count_up_to(const vector & vec, int up_to) { return upper_bound(vec.begin(), vec.end(), up_to) - vec.begin(); } int count_interval(const vector & vec, int low, int high) { return count_up_to(vec, high) - count_up_to(vec, low - 1); } void test_case() { int n, q; scanf("%d%d", &n, &q); set ends; for(int i = 1; i <= n; ++i) { scanf("%d", &in[i]); if(i != 1 && in[i-1] == in[i]) score[i] = score[i-1] + 1; else score[i] = 1; inv[score[i]].push_back(i); } for(int i = 1; i <= n; ++i) if(i == n || in[i] != in[i+1]) ends.insert(i); while(q--) { int low, high, k; scanf("%d%d%d", &low, &high, &k); int end = *ends.lower_bound(low); int answer = 0; if(end + 1 <= high) answer += count_interval(inv[k], end + 1, high); if(min(end, high) - low + 1 >= k) ++answer; printf("%d\n", answer); } for(int i = 1; i <= n; ++i) inv[score[i]].clear(); } int main() { int T; scanf("%d", &T); while(T--) test_case(); }