There are multiple problems with your code. I recommend you to fix one problem at a time and run the code so you really understand what was wrong with it.
The ‘return 0;’ should be outside the for loop because otherwise your program would just run for 1 test case then terminate.
Don’t print the answer as “factorial is%d” because the output format doesn’t specify anything like that. Instead, just print the number without any words.
Put a ‘\n’ after printing the answer. Even if you were getting the correct answer the numbers would be concatenated together. For example the answer for the sample test case would be printed as 624120.
In this problem, n can be as large as 20 and 20! is around 2\cdot 10^{18} but the max value you can store in the int datatype is around 2 \cdot 10^9 so it will overflow and give a wrong answer.
Also don’t write your code in the question. Just post a link to your submission which you can find by clicking on “My submissions” on the problem page.
And lastly, don’t get discouraged at any point; Instead, learn from your mistakes. Have fun coding!