In a room there are some chairs with 4 legs and some stools with 3 legs. When each chair and stool has one person sitting on it, then in the room there are a total of 39 legs. How many chairs and stools are there in the room?