Natsume loves big cats. Natsume decided to head to a corner of the schoolyard where stray cats always gather in order to brush the stray cats, which is a daily routine today.

N cats gathered at the spot today. Natsume wanted to brush everyone, but suddenly she was able to do something just before she came there, and she could only brush one in time. Every cat is looking forward to brushing, so if you do only one cat, the other cats will be jealous. So, in order to convince the cats, I decided to decide which cat to brush with Amidakuji.

Amidakuji consists of n vertical lines and m pre-drawn horizontal lines. The horizontal line must connect two adjacent vertical lines so that they are perpendicular to them. Also, horizontal lines must not share endpoints. There is a hit mark at the bottom of one vertical line. An example of Amidakuji that meets these conditions is shown in the figure (these correspond to the sample input example).

Diagram of Amidakuji given in the sample input example
Figure: Example of Amidakuji that meets the condition of the problem

Each cat chooses one from the top of the vertical line. And as a result of following the Amidakuji, the rule is that the winning cat can get the right to brush today. Natsume immediately created the Amidakuji. Vertical lines, horizontal lines, and hits were written and hidden so that the horizontal lines could not be seen.

When it was time for the cats to choose, Natsume noticed that among the n cats, there was a stray cat, Actagawa, who normally does not show his face. Actagawa hasn't brushed for another month and his hair is stiff.

Natsume feels sorry for the other cats, but decides to cheat and brush the Actagawa. First, ask the cats to choose the vertical line as usual. When everyone has finished choosing, Natsume secretly adds some horizontal lines and changes the ghost leg so that Actagawa hits.

However, depending on the vertical lines chosen by Actagawa, there are too many horizontal lines to draw in order to hit Actagawa, and the cats may lose their plans while working. Therefore, Natsume first decided to find out how many horizontal lines should be drawn for each vertical line if Actagawa chose it.

In addition, the newly drawn horizontal line must also connect two adjacent vertical lines perpendicularly to them, and must be drawn so that the horizontal lines do not share the end points.

Notes on Submission

Multiple datasets are given in the above format. The first line of input data gives the number of datasets. Create a program that outputs the output for each data set in order in the above format.



Input

Input data is given in the following format.

n m k
h1 x1
h2 x2
...
hm xm

The number of vertical lines n (1 ≤ n ≤ 100000), the number of horizontal lines already drawn m (0 ≤ m ≤ 100000), and the number of vertical lines per k (1 ≤ k ≤ n) on the first line of the input Is given. Here, the numbers of the vertical lines are 1, 2, ..., n in order from the left.

The following m lines are given horizontal line information. Each line is given two integers h (1 ≤ h ≤ 1000000) and x (1 ≤ x ≤ n -1) that represent the information of one horizontal line. h is the distance from the lower end of the vertical line, and x is the number of the vertical line on the left side of the vertical lines connected by the horizontal line. In other words, this horizontal line connects the xth and x + 1th vertical lines.

In the input, the horizontal line exists only at the position of the integer height, but the position of the newly added horizontal bar does not necessarily have to be the position of the integer height.

Output

Output an n-line string. On the i (1 ≤ i ≤ n) line, output the minimum number of horizontal lines that must be added to hit the actor when the actor chooses the i-th vertical line.

Example

Input

4
3 2 1
20 1
10 2
5 7 3
70 1
60 4
50 2
40 4
30 1
20 3
10 2
1 0 1
4 2 1
10 1
10 3


Output

1
0
1
1
0
1
1
2
0
1
0
1
2
#include<iostream>
#include<queue>
#include<vector>
#include<algorithm>
using namespace std;

#define fr first
#define sc second

const int INF=1000000000;

struct SEG{
    int siz;
    int s[1<<18];
    void init(){
        siz = 1<<17;
        for(int i=0;i<2*siz-1;i++){
            s[i]=INF;
        }
    }
    void updata(int a,int b,int x,int k,int l,int r){
        if(b <= l || r <= a)return;
        if(a <= l && r <= b){
            s[k] = min ( s[k] , x );
            return;
        }
        updata(a,b,x,2*k+1,l,(l+r)/2);
        updata(a,b,x,2*k+2,(l+r)/2,r);
    }
    void _updata(int a,int x,int k,int l,int r){
        if(a+1 <= l || r <= a)return;
        if(a==l&&r==a+1){
            s[k] = x;
            return;
        }
        updata(l,r,s[k],2*k+1,l,(l+r)/2);
        updata(l,r,s[k],2*k+2,(l+r)/2,r);
        s[k] = INF;
        _updata(a,x,2*k+1,l,(l+r)/2);
        _updata(a,x,2*k+2,(l+r)/2,r);
    }
    int query(int a){
        a += siz-1;
        int ret = s[a];
        while(a > 0){
            a = (a-1)/2;
            ret = min ( ret , s[a] );
        }
        return ret;
    }
}dp[2];

int main(){
    int T;
    scanf("%d",&T);
    for(int test=0;test<T;test++){
        static int n,m,k;
        static int h[100010],x[100010];
        scanf("%d%d%d",&n,&m,&k);
        for(int i=0;i<m;i++){
            scanf("%d%d",&h[i],&x[i]);
        }
        
        pair<int,int> p[100010];
        for(int i=0;i<m;i++){
            p[i]=pair<int,int>(h[i],x[i]);
        }
        sort(p,p+m);
        
        dp[0].init();
        dp[1].init();
        dp[0].updata(k,n+1,-k,0,0,dp[0].siz);
        dp[1].updata(1,k+1,k,0,0,dp[1].siz);
        
        int t=0;
        int now=k;
        for(int i=0;i<m;i++){
            int c[2] = {1,-1};
            if(p[i].sc == now)now++;
            else if(p[i].sc+1 == now)now--;
            for(int j=0;j<2;j++){
                int memo=dp[j].query(p[i].sc);
                dp[j]._updata(p[i].sc,min(dp[j].query(p[i].sc+1)+c[j],abs(now-p[i].sc)-p[i].sc*c[j]),0,0,dp[j].siz);
                dp[j]._updata(p[i].sc+1,min(memo-c[j],abs(now-p[i].sc-1)-(p[i].sc+1)*c[j]),0,0,dp[j].siz);
            }
            
            if(i+1<m&&p[i].fr==p[i+1].fr)continue;
            for(;t<=i;t++){
                dp[0].updata(p[t].sc+1,n+1,min(dp[0].query(p[t].sc+1),dp[1].query(p[t].sc+1)-2*(p[t].sc+1)),0,0,dp[0].siz);
                //dp[1].updata(1,p[t].sc+2,min(dp[0].query(p[t].sc+1)+2*(p[t].sc+1),dp[1].query(p[t].sc+1)),0,0,dp[0].siz);
                //dp[0].updata(p[t].sc,n+1,min(dp[0].query(p[t].sc),dp[1].query(p[t].sc)-2*p[t].sc),0,0,dp[1].siz);
                dp[1].updata(1,p[t].sc+1,min(dp[0].query(p[t].sc)+2*p[t].sc,dp[1].query(p[t].sc)),0,0,dp[1].siz);
                dp[0].updata(p[t].sc-1,n+1,min(dp[0].query(p[t].sc-1),dp[1].query(p[t].sc-1)-2*(p[t].sc-1)),0,0,dp[0].siz);
                //dp[1].updata(1,p[t].sc,min(dp[0].query(p[t].sc-1)+2*(p[t].sc-1),dp[1].query(p[t].sc-1)),0,0,dp[0].siz);
                //dp[0].updata(p[t].sc+2,n+1,min(dp[0].query(p[t].sc+2),dp[1].query(p[t].sc+2)-2*(p[t].sc+2)),0,0,dp[1].siz);
                dp[1].updata(1,p[t].sc+3,min(dp[0].query(p[t].sc+2)+2*(p[t].sc+2),dp[1].query(p[t].sc+2)),0,0,dp[1].siz);
            }
        }
        
        for(int i=1;i<=n;i++){
            printf("%d%c",min(dp[0].query(i)+i,dp[1].query(i)-i),10);
        }
    }
}