import java.util.*;

public class B {
    public static void main(String[] args) {
        Scanner input = new Scanner(System.in);
        int t = input.nextInt();
        for (int h = 0; h < t; h++) {
            int n = input.nextInt();
            int m = input.nextInt();
            int[] d1 = new int[n+1];
            int[] d2 = new int[n+1];
            int[] a = new int[n+1];
            int[] b = new int[n+1];
            int[] c = new int[n+1];
            int[] s = new int[n+1];
            for (int i = 0; i < m; i++) {
                int u1 = input.nextInt();
                int u2 = input.nextInt();
                a[u1] = 1;
                if (b[u2] == 0 || b[u2] > u1) b[u2] = u1;
                if (c[u2] == 0 || c[u2] < u1) c[u2] = u1;
                s[u1]++;
                if (u2 < n) s[u2+1]--;
            }
            int bb = 0;
            for (int i = n; i >= 1; i--) {
                if (bb == 0 || (b[i] != 0 && b[i] < bb)) bb = b[i];
                if (bb > i) bb = 0;
                b[i] = bb;
            }
            int cc = 0;
            for (int i = 1; i <= n; i++) {
                int q = c[i];
                c[i] = cc;
                if (q > cc) cc = q;
            }
            int ss = 0;
            for (int i = 1; i <= n; i++) {
                ss += s[i];
                s[i] = ss;
            }
            d1[0] = 0;
            d2[0] = 0;
            for (int i = 1; i <= n; i++) {
                if (s[i] == 0) {
                    d1[i] = d1[i-1];
                    d2[i] = 1+d2[i-1];
                    if (d2[i-1] == -1) d2[i] = -1;
                    continue;
                }
                int x1 = -1, x2 = -1;
                if (a[i] != 1) {
                    x1 = d1[i-1];
                    x2 = d2[i-1];
                }
                int y1 = -1, y2 = -1;
                if (c[i] < b[i]) {
                    y1 = d1[b[i]-1]+1;
                    if (d1[b[i]-1] == -1) y1 = -1;
                    y2 = d2[b[i]-1]+1;
                    if (d2[b[i]-1] == -1) y2 = -1;
                }
                if (x1 == -1 && y1 == -1) d1[i] = -1;
                else if (x1 == -1) d1[i] = y1;
                else if (y1 == -1) d1[i] = x1;
                else d1[i] = Math.min(x1,y1);
                if (x2 == -1 && y2 == -1) d2[i] = -1;
                else if (x2 == -1) d2[i] = y2;
                else if (y2 == -1) d2[i] = x2;
                else d2[i] = Math.max(x2,y2);
            }
            System.out.println(d1[n] + " " + d2[n]);
        }
    }
}
