Macbeth

Given n time intervals and w witches, each witch predicts a chain of non-overlapping intervals, so find the maximum number of intervals coverable by w chains.

Medium6IntervalsGreedyDynamic programmingNo attempts yetTime limit2sMemory limit512 MB

Problem

Macbeth is a loyal follower of the king, and he has just fought well in a battle. Then he meets three witches. They predict that he is about to be promoted, and that he will become king after that. The promotion happens exactly as predicted, so Macbeth starts to believe that he is destined to be king. He and his wife go blind with ambition, murder the king, and murder almost everyone they see as a threat or a rival.

The witches held that much power over Macbeth because their prediction was right. Macbeth should have asked for more than one prediction and made their job harder. Predicting with a crystal ball is hard work. A ball is fussy about when it lets you predict a particular event, and some predictions take longer than others. Working out how to make the largest number of predictions together is a difficult task for the witches.

Every event comes with one time interval. To predict event ii, one witch has to look into her crystal ball for the whole interval [si,ti][s_i, t_i] while thinking about event ii only. So even when two events share the same interval, a single witch predicts only one of them. A witch who has predicted event ii can predict event jj next only when tisjt_i \le s_j. The witches coordinate so that the total number of predicted events is as large as possible.

Given ww witches, find the maximum number of events they can predict.

Input

The first line contains the number of data sets K1K \ge 1. Then KK data sets follow, each in the format below.

The first line of a data set contains two integers nn and ww. 0n10000 \le n \le 1000 is the number of events and 1w101 \le w \le 10 is the number of witches.

Each of the next nn lines contains two integers sis_i and tit_i describing one event (0si<ti1070 \le s_i < t_i \le 10^7).

Output

For each data set, first print Data Set x: on a line by itself, where xx is the number of the data set counting from 1. On the next line print the maximum number of events the witches can predict.

Print one blank line after each data set.