#include <iostream> using namespace std; int main() { int T, n, m; cin >> T; while (T--) { cin >> n >> m; int num[n + 10], search[n + 10][2], dp[n + 10]; fill(dp, dp + n, 0); for (int i = 1; i <= n; ++i) cin >> num[i]; for (int i = 0; i < m; ++i) { cin >> search[i][0] >> search[i][1]; int ans = 0; for (int j = search[i][0]; j <= search[i][1]; j++) { dp[j] = 1; for (int k = search[i][0]; k < j; k++) if (num[k] < num[j] && j - k == 1) dp[j] = max(dp[j], dp[k] + 1); ans = max(ans, dp[j]); } cout << ans << endl; } } return 0; }