Please help me to optimize the following C code:

```
#include <stdio.h>
#include <stdlib.h>
int main(){
int p,q,n,i,j,k,l;
printf("\n please enter the no. of test cases");
scanf("%d",&n);
for(k=0;k<n;k++){
printf("\n please enter the numbers.\n");
scanf("%d %d",&p,&q);
printf("\n Prime numbers between %d and %d.\n",p,q);
if(p>q)
{
int t = p;
p=q;
q=t;
}
if(p==2 || p == 1 && q != 1)
printf("\t 2");
if(p%2 == 0)
p = p+1;
if(q==2)
printf("\t 2");
if(q%2 == 0)
q = q-1;
for(i=p;i<=q;i=i+2)
{
l = i/2;
if(l == 1)
l=2;
for(j=2;j<=l;j++)
{
if(i%j == 0)
break;
if(j==l)
printf("\t %d",i);
}
}
}
return 0;
}
```