CJam, 4242 40 bytes
S"wertyuiopasdfghjklzxcvbnm"9/Sf*N*+q/W=1> or
S"wertyuiopasdfghjklzxcvbnm"9"wertyuiop asdfghjkl zxcvbnm"q/Sf*N*+_q#))>W=S%Sf*N* &input=f" rel="nofollow noreferrer">Test it here.Test it here.
Explanation
S e# Push a space. "we...nm" e# Push the letters in order, without q. We don't need q, because it will never e# be part of the output, and by omitting it, the first two lines have the same e# length, which comes handy when we... 9/ e# Split the string into chunks of 9 characters. Sf* e# Join each line by spaces. N* e# Join the lines by linefeeds. + e# Prepend the space we pushed earlier. The resulting string now has the correct e# layout and a single whitespace character in front of each letter. q/ e# Split thatthe string around the input. If the input is "q", the entire string e# will go into a single chunk. W= e# Select the last chunk. 1>S% e# DiscardSplit the firststring characteraround spaces, discarding empty segments (ifonly thererelevant isfor one),the which is e# first segment if the whitespaceinput inis front"p" or "l"). Sf* e# Join each e#line ofby thespaces. N* first letter wee# wantJoin tothe printlines by linefeeds. The other version works quite similarly, but instead of splitting the string, we find the position of the input with # (which gives -1) for q and then discard everything up to that position + 2.