Who To Query
Who to query is one of the most personal things you can decide! It's like deciding who to be friends with or who to have a staring contest with or who to share a house with only not because this friend is also somebody you're doing business with and they're going to be your champion so it's kind of a weird special relationship beyond friendship. There's no right way to choose who to query, publisher or agent, but I guess there are some good places to look.
Query tracker is an excellent place to start, both on the forums for advice and then on their database for info. They have a lot of info crammed into one location meaning you can find agents who rep your genre (and publishers who publish it), read interviews with them, and basically get to know them ahead of time as well as know who else they represent! It's free, because the folks over there know that most of us have no money, but there is a paid for option that looks super fabulous too for when you find some change down the back of the sofa or grandma gives you an etc tenner for no real reason and what a world we live in.
Okay, so at some point on your mission to query fabulousness things are going to get ugly. There will be some sifting through deep dark places on google looking for the vaguest whiff of a mention of that agent or publisher you've been researching and that's okay! Provided you realise they will do exactly the same to you once they come across your query. Like, as long as you know a little light stalking in this situation is a two way street that will be crossed repeatedly, then go ahead! Google away. Here's a link to a guide that will give you advance googling skills better than even Mr Robot.
This is actually a brilliant place to find things out from (and discover agents and publishers!). A lot of agents use the hashtag #MSWL (manuscript wish list.... sometimes I forget what it stands for and make up my own names like manuscript wet latte and manuscript wig lovers but those are both wrong so don't get confused like me) to talk about what they'd love to see right now or forever and ever again and again so you could start there and find a person talking about what you have to offer. IMHO Twitter is also a great place to get the measure of a person (just remember that people can get the measure of you too from your account!). Maybe they tweet the below gif a lot, maybe they love it just like you do and that's perfect because you not only need a business partner but somebody who just gets you.
Ask Your Pals
Sometimes just asking around can be a good thing too, you know? If you know people who have queried and they write in your genre and you get on with them they'll also probably know the good, bad, and wonderful of the publishing world. Pals in the writing world cannot be over-stressed! They are essential.
Honorary mention because obvs don't look for agents or publishers here and decide to query them but it's always good to be safe! Check that people don't turn up here before you commit to them! It can be dangerous out there so it's always better to be safe. This is a website dedicated to reporting professional puddles of pee in publishing and making sure they don't ensnare innocent lovely people.
How to you choose who to pitch to?