I've been trying to improve my Japanese by translating a children's book. I only studied Japanese for a short while over 10 years ago so my grammar knowledge is very flawed and I've never read books before, only manga, so I mostly only know the basic grammar used in everyday conversations.

「どうしてないているの？」とるるちゃんがきくと、
「おさんぽをしていたら、おうちにかえれなくなったの。」とちいさなおばけはこたえました。

I'm confused to the use of と here. All three of them. I can understand what it says without knowing, but I really want a better understanding the usage of と here.