><>, 3232 30 bytes
"@!qx:q:"ooi~i~i~i{=?;o!o!ox~oo;
Try it online!
Explanation
"@!qx:q:"ooi~i~i~i{=?;o!ox~oo;
"@!qx:q:" Push @!qx:q: on the stack (in reverse)
oo Print :q [stack: @!qx:]
i~i~i~ Remove first 3 input characters
i Load @ or : from the input (= i)
{ Shift stack to the left [stack: !qx:i@]
=? If 4th character was @
; Exit
Else
o Print :
!o Jump to
x Random direction (left or right because
up and down retrigger x)
Left:
;o!o Print x and exit.
Right:
~oo; Remove x, print q! and exit.