import java.io.IOException;
import java.util.Scanner;

/**
 * ACM Training 2009
 * ACM Problem #191 - Intersection
 * Link: http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=3&page=show_problem&problem=127
 *
 * @author Felix Dietrich
 * @version 1.0, 09/03/2009
 *
 * Methode: Interpolation
 * Status : Accepted
 * Runtime: 0.152
 */

public class Main
{
    public static class Point
    {
        double x,y;
        
        public Point(int xstart, int ystart, int xend, int yend, double i)
        {
            x = xstart + (xend-xstart) * i;
            y = ystart + (yend-ystart) * i;
        }
        
        @Override
        public String toString() {
            return String.format("%.03f | %.03f", x,y);
        }

    }

    public static void main(String... s) throws IOException
    {
        Scanner scan = new Scanner(System.in);
        
        int cases = scan.nextInt();
        
        for(int c=0; c<cases; c++)
        {
            /////////////////////////
            // READ INFO
            
            int xstart = scan.nextInt();
            int ystart = scan.nextInt();
            int xend = scan.nextInt();
            int yend = scan.nextInt();
            
            int xleft = scan.nextInt();
            int ytop = scan.nextInt();
            int xright = scan.nextInt();
            int ybottom = scan.nextInt();

            /////////////////////////
            // CALC
            
            boolean isInRect = false;
            
            // Interpolate
            for(double i=0.0; i<=1.0; i+=0.0001)
            {
                // If the interpolated point is in the rectangle, the line intersects the rectangle.
                if(inRect(new Point(xstart,ystart,xend,yend,i), xleft,ytop,xright,ybottom))
                {
                    //System.out.println(new Point(xstart,ystart,xend,yend,i));
                    isInRect = true;
                    break;
                }
            }
            
            if(isInRect)
                System.out.println("T");
            else
                System.out.println("F");
        }
    }

    private static boolean inRect(Point point, int xleft, int ytop,
            int xright, int ybottom)
    {
        if(point.x >= Math.min(xleft,xright)
                && point.x <= Math.max(xleft,xright)
                && point.y >= Math.min(ytop,ybottom)
                && point.y <= Math.max(ytop,ybottom))
            return true;
        return false;
    }
}

2.

import java.io.BufferedOutputStream;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.StringTokenizer;

/**
* ACM Training 2009
* ACM Problem #191 - Intersection
* Link: http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=3&page=show_problem&problem=127
*
* @author Dennis Wilfert
* @version 1.0, 09/06/2009
*
* Status : Accepted
* Runtime: 0.080
*/
public class Intersection {

public static void main(String... strings) throws NumberFormatException, IOException {

BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
PrintWriter writer = new PrintWriter(new BufferedOutputStream(System.out));

StringTokenizer token;

int cases = Integer.parseInt(reader.readLine());
double[][] coordinates = new double[4][4];
double x, y;
int i;
double[] lineSorted = new double[4];
while (cases > 0) {

token = new StringTokenizer(reader.readLine());

for (i = 0; i < 4; i++) {
coordinates[i][0] = Integer.parseInt(token.nextToken());
coordinates[i][1] = Integer.parseInt(token.nextToken());
}

// Koordinaten des Rechtecks sortieren
// coordinates[2] ist links oben coordinates[3] ist rechts unten
if (coordinates[2][1] < coordinates[3][1]) {
if (coordinates[2][0] > coordinates[3][0]) {
x = coordinates[3][0];
y = coordinates[3][1];
coordinates[3][0] = coordinates[2][0];
coordinates[3][1] = coordinates[2][1];
coordinates[2][0] = x;
coordinates[2][1] = y;
} else {
y = coordinates[2][1];
coordinates[2][1] = coordinates[3][1];
coordinates[3][1] = y;
}
} else {
if (coordinates[2][0] > coordinates[3][0]) {
x = coordinates[3][0];
coordinates[3][0] = coordinates[2][0];
coordinates[2][0] = x;
}
}

// Koordinaten der Geraden nach größe sortieren [0] kleines x [1] großes x [2] kleines y [3] großes y
lineSorted[0] = coordinates[0][0] < coordinates[1][0] ? coordinates[0][0] : coordinates[1][0];
lineSorted[1] = coordinates[0][0] > coordinates[1][0] ? coordinates[0][0] : coordinates[1][0];
lineSorted[2] = coordinates[0][1] < coordinates[1][1] ? coordinates[0][1] : coordinates[1][1];
lineSorted[3] = coordinates[0][1] > coordinates[1][1] ? coordinates[0][1] : coordinates[1][1];

// Sonderfall, die Gerade liegt komplett im Kreis
if (lineSorted[0] > coordinates[2][0] && lineSorted[1] < coordinates[3][0] && lineSorted[2] > coordinates[3][1] && lineSorted[3] < coordinates[2][1]) {
writer.println('T');
} else {
// Sonderfall, die gerade ist parallel zur x-Achse
if (coordinates[0][0] == coordinates[1][0]) {
if (((lineSorted[3] >= coordinates[2][1] && coordinates[2][1] >= lineSorted[2]) || (lineSorted[3] >= coordinates[3][1] && coordinates[3][1] >= lineSorted[2]))) {
writer.println('T');
} else {
if ((lineSorted[0] == coordinates[2][0] || lineSorted[0] == coordinates[3][0]) && (lineSorted[2] < coordinates[2][1] && lineSorted[2] > coordinates[3][1])) {
writer.println('T');
} else {
writer.println('F');
}
}
} else {
// Sonderfall, die gerade ist parallel zur y-Achse
if (coordinates[0][1] == coordinates[1][1]) {
if (((lineSorted[1] >= coordinates[2][0] && coordinates[2][0] >= lineSorted[0]) || (lineSorted[1] >= coordinates[3][0] && coordinates[3][0] >= lineSorted[0]))) {
writer.println('T');
} else {
if ((lineSorted[2] == coordinates[2][1] || lineSorted[2] == coordinates[3][1]) && (lineSorted[0] > coordinates[2][0] && lineSorted[0] < coordinates[3][0])) {
writer.println('T');
} else {
writer.println('F');
}
}

} else {
// Geradengleichung berechnen
// m
coordinates[0][2] = (coordinates[1][1] - coordinates[0][1]) / (coordinates[1][0] - coordinates[0][0]);
// n
coordinates[0][3] = coordinates[1][1] - coordinates[0][2] * coordinates[1][0];

// Durch einsetzen der Koordinaten des Rechtecks prüfen, ob eine der 4 Geraden des Rechtecks geschnitten wird
switch (1) {
case 1:
y = coordinates[0][2] * coordinates[2][0] + coordinates[0][3];
if (coordinates[2][1] >= y && y >= coordinates[3][1] && lineSorted[2] <= y && lineSorted[3] >= y) {
writer.println('T');
break;
}
case 2:
y = coordinates[0][2] * coordinates[3][0] + coordinates[0][3];
if (coordinates[3][1] <= y && y <= coordinates[2][1] && lineSorted[2] <= y && lineSorted[3] >= y) {
writer.println('T');
break;
}
case 3:
x = (coordinates[2][1] - coordinates[0][3]) / coordinates[0][2];
if (coordinates[2][0] <= x && x <= coordinates[3][0] && lineSorted[0] <= x && lineSorted[1] >= x) {
writer.println('T');
break;
}
case 4:
x = (coordinates[3][1] - coordinates[0][3]) / coordinates[0][2];
if (coordinates[2][0] <= x && x <= coordinates[3][0] && lineSorted[0] <= x && lineSorted[1] >= x) {
writer.println('T');
break;
}
default:
writer.println('F');
}
}
}
}
cases--;

}
writer.flush();
}
}