Task: Program Execution
Input (English): n, q, 397, 387, l, p
Output (English): 3, 7, 8, 9