Let the number of girls in Team A be 3x and the number of boys in Team A be x.
Let the number of girls in Team B be 5y and the number of boys in Team B be 2y.
The total number of participants is 2(x + 3x + 5y + 2y) = 2(4x + 7y)
The ratio of the number of girls to the number of boys is (3x + 5y) : (x + 2y)
(3x + 5y) : (x + 2y) = (3/4)(4x + 7y) : (1/4)(4x + 7y)
(3x + 5y) : (x + 2y) = 3 : 1
Therefore, the ratio of the number of girls to the number of boys participating in the carnival is 3:1.