void clearPattern() {
    for (int i = 0; i < 24; i++) {
        colorBlack();
    }

    __delay_ms (10);
}
int main(){
    int t , n, xini , yini , xfin , yfin, q ,dif1 , dif2;
    scanf("%d" , &t );
    while( t-- ){
        scanf("%d %d" , &q , &n );
        while( q-- ){
            scanf("%d %d %d %d" , &xini , &yini , &xfin  ,&yfin );
            if( xini <= 0 || xini > n || yini <= 0 || yini > n || xfin <= 0 || xfin >n || yfin <= 0 || yfin > n ){
                puts("no move");
                continue;
            }

            if( xini == xfin && yini == yfin )puts("0");
            else if( abs( xini - xfin ) == abs( yini - yfin ) )puts("1");
            else if( ( xini + yini ) == ( xfin + yfin ) )puts("1");
            else if( colorWhite( xini , yini , xfin , yfin ) || colorBlack( xini , yini , xfin , yfin ) )puts("2");
            else puts("no move");
        }
    }

    return 0;
}
void buildImageMask( const VectorImageFeaturePrediction &inlierPredictions,
                     cv::Mat &imageMask )
{
    // Filtramos las zonas alrededor de cada prediccion
    size_t inlierPredictionsSize = inlierPredictions.size();

    cv::Scalar colorBlack(0, 0, 0);

    // Para cada prediccion, se dibuja dentro de la mascara su elipse de incertidumbre
    // De esta forma se previene el hecho de agregar nuevos features dentro de
    // elipses de busqueda de features anteriores
    for (int i = 0; i < inlierPredictionsSize; ++i)
    {
        ImageFeaturePrediction *inlierPrediction = inlierPredictions[i];

        drawUncertaintyEllipse2D( imageMask,
                                  cv::Point2d(inlierPrediction->imagePos[0], inlierPrediction->imagePos[1]),
                                  inlierPrediction->covarianceMatrix,
                                  2 * (imageMask.rows + imageMask.cols),
                                  colorBlack,
                                  true );
    }
}
void WorkPlaceWidget::drawRelation(Relation* r, bool focus){
    Entitie* eR = r->getEntR();
    Entitie* eL = r->getEntL();
    this->calculateEntitie(eL);
    this->calculateEntitie(eR);
    int x1 = ((IntField*)eR->fieldByID("X"))->getValue();
    int y1 = ((IntField*)eR->fieldByID("Y"))->getValue();
    int w1 = ((IntField*)eR->fieldByID("W"))->getValue();
    int h1 = ((IntField*)eR->fieldByID("H"))->getValue();
    int t1 = ((IntField*)eR->fieldByID("T"))->getValue();
    int x2 = ((IntField*)eL->fieldByID("X"))->getValue();
    int y2 = ((IntField*)eL->fieldByID("Y"))->getValue();
    int w2 = ((IntField*)eL->fieldByID("W"))->getValue();
    int h2 = ((IntField*)eL->fieldByID("H"))->getValue();
    int t2 = ((IntField*)eL->fieldByID("T"))->getValue();

    int alpha = 250;
    int alpha0 = 25;
    int alpha1 = 100;
    int alpha2 = 250;
    if((x1-w2-15<x2)&&(y1-h2-15<y2)&&(w1+x1+15>x2)&&(h1+y1+15>y2)){
        alpha = 0;
        alpha0 = 0;
        alpha1 = 0;
        alpha2 = 0;
    }

    QPainter painter(this);
    QColor color(90,185,255,alpha);
    QColor colorGreenAlpha(55,155,55,alpha0);
    QColor colorBlackAlpha(0,0,0,alpha1);
    QColor colorBlack(0,0,0,alpha2);
    QPen penf = QPen(colorBlackAlpha, 1, Qt::SolidLine);

    painter.setBrush(QBrush(color));

    int indexR = 0;
    int indexL = 0;
    for(int j=0; j<eR->fieldCount() && indexR==0; j++){
        if(eR->fieldAt(j)->getID()==r->getKey()){
            indexR = j;
        }
    }
    for(int j=0; j<eL->fieldCount() && indexL==0; j++){
        if(eL->fieldAt(j)->getID()==r->getKey()){
            indexL = j;
        }
    }
    if(indexR<work_count-1){
        indexR=work_count-1;
    }
    if(indexL<work_count-1){
        indexL=work_count-1;
    }

    int x01=0;
    int x02=0;
    int y01=0;
    int y02=0;
    if(qAbs(x1-x2)>=w2 && qAbs(x1-x2)>=w1){
        if(x1>x2){
            x01=x1;
            x02=x2+w2+1;
        }else{
            x02=x2;
            x01=x1+w1+1;
        }
        y01 = y1+(indexR+1-work_count)*24+((indexR+1-(work_count-1))*24-(indexR+1-work_count)*24)/2;
        y02 = y2+(indexL+1-work_count)*24+((indexL+1-(work_count-1))*24-(indexL+1-work_count)*24)/2;
    }else{
        if(y1>y2){
            y01=y1;
            y02=y2+h2+1;
        }else{
            y02=y2;
            y01=y1+h1+1;
        }
        x01=x1+w1/2;
        x02=x2+w2/2;
    }
    int x0 = 0;
    int y0 = 0;
    QPointF p1(x01,y01);
    QPointF p2(x02,y02);
    if(x01>x02){
        x0 = x02 + (x01 - x02)/2;
    }else{
        x0 = x01 + (x02 - x01)/2;
    }
    if(y01>y02){
        y0 = y02 + (y01 - y02)/2;
    }else{
        y0 = y01 + (y02 - y01)/2;
    }
    QPointF p0(x0,y0);
    QPen pen1 = QPen(colorBlack, 1, Qt::DotLine);
    QPen pen2 = QPen(colorBlack, 1, Qt::SolidLine);
    QPen pen3 = QPen(colorBlack, 2, Qt::SolidLine);
    QPen pen4 = QPen(colorBlack, 2, Qt::DotLine);
    if(r->getAbsL()){
        if(focus){
            painter.setPen(pen4);
        }else{
            painter.setPen(pen1);
        }
    }else{
        if(focus){
            painter.setPen(pen3);
        }else{
            painter.setPen(pen2);
        }
    }
    painter.drawLine(p1,p0);
    if(r->getAbsR()){
        if(focus){
            painter.setPen(pen4);
        }else{
            painter.setPen(pen1);
        }
    }else{
        if(focus){
            painter.setPen(pen3);
        }else{
            painter.setPen(pen2);
        }
    }
    painter.drawLine(p0,p2);
    if(focus){
        painter.setPen(pen3);
    }else{
        painter.setPen(pen2);
    }
    painter.drawEllipse(p0, 10, 10);
    if(r->getMulL()){
        QRect tr(p0.x()-7,p0.y()-7,12,12);
        painter.drawText(tr,"n");
    }
    if(r->getMulR()){
        QRect tr(p0.x()+3,p0.y()-7,12,12);
        painter.drawText(tr,"n");
    }
    painter.setPen(pen2);
    painter.drawLine(QPointF(p0.x(),p0.y()-10),QPointF(p0.x(),p0.y()+10));
    if(focus){
        if(t1!=1){
            double distance = this->core->getDistanceOf(eR);
            painter.setBrush(QBrush(colorGreenAlpha));
            painter.setPen(penf);
            painter.drawEllipse(QPoint(x1-1,y1-1), (int)qRound(distance), (int)qRound(distance));
         }
        if(t2!=1){
            double distance = this->core->getDistanceOf(eL);
            painter.setBrush(QBrush(colorGreenAlpha));
            painter.setPen(penf);
            painter.drawEllipse(QPoint(x2-1,y2-1), (int)qRound(distance), (int)qRound(distance));
         }
    }
}