Task: Program Execution
Input (English): Q, n, 3017, B, 4703, 3511, p
Output (English): 17, 14, 3017, 2, 4703, 3511, 16