// Arup Guha
// 6/12/2023
// Solution to Kattis Problem: Nine Knights
// https://open.kattis.com/problems/nineknights

// 6/8/2026 - alternate solution idea coded in class, old file modified

using namespace std;
#include <bits/stdc++.h>

// Useful constants.
const int N = 5;

// Global grid
vector<string> grid;

// Function prototypes.
bool twoAttack(vector<pair<int,int>>& locs);

int main() {

    string tmp;
    int numK = 0;

    // We store the row, column location of each knight here.
    vector<pair<int,int>> loc;

    // Now read in the grid, we never really fully need to store it...
    for (int i=0; i<N; i++) {
        cin >> tmp;
        grid.push_back(tmp);
        for (int j=0; j<N; j++) {
            if (grid[i][j] == 'k') {

                // Add this orderd pair to the knights.
                loc.push_back(pair<int,int>{i,j});

                // Add 1...
                numK++;
            }
        }
    }

    // Check both conditions...
    if ( (numK == 9) && !twoAttack(loc))
        cout << "valid" << endl;
    else
        cout << "invalid" << endl;

    return 0;
}

// Returns true iff any knight can attack another knight.
bool twoAttack(vector<pair<int,int>>& locs) {

    // This is how we loop through all distinct pairs of objects in a list.
    for (int i=0; i<locs.size(); i++) {

        // We can just start aht index i+1, do you see why?
        for (int j=i+1; j<locs.size(); j++) {

            // Get delta between the knights.
            int dr = abs(locs[i].first - locs[j].first);
            int dc = abs(locs[i].second - locs[j].second);

            // They can attack each other.
            if ((dr == 1 && dc == 2) || (dr==2 && dc==1))
                return true;
        }
    }

    // If we get here, no two knights attack each other.
    return false;
}
