// Arup Guha
// 6/13/2024
// Solution to Kattis Problem: Star Battles
// https://open.kattis.com/problems/starbattles1

using namespace std;
#include <bits/stdc++.h>

// Important constants.
const int SIZE = 10;
const int MAGIC = 2;

// Movement directions.
const vector<int> DX = {-1,-1,-1,0,0,1,1,1};
const vector<int> DY = {-1,0,1,-1,1,-1,0,1};

// Store input here.
vector<vector<int>> grid(SIZE, vector<int>(SIZE));
vector<string> res(SIZE);

// Run the four tests.
bool rows();
bool cols();
bool regions();
bool adj();
bool inbounds(int x, int y);

int main() {

    string tmp;

    // Read in the first grid. Store digits as integers.
    for (int i=0; i<SIZE; i++) {
        cin >> tmp;
        for (int j=0; j<SIZE; j++)
            grid[i][j] = tmp[j]-'0';
    }

    // Store result.
    for (int i=0; i<SIZE; i++)
        cin >> res[i];

    // Ta da!
    if (rows() && cols() && regions() && adj())
        cout << "valid" << endl;
    else
        cout << "invalid" << endl;

    return 0;
}

bool rows() {

    for (int i=0; i<SIZE; i++) {

        // Count stars on row i.
        int cnt = 0;
        for (int j=0; j<SIZE; j++)
            if (res[i][j] == '*')
                cnt++;

        // This is bad.
        if (cnt != MAGIC) return false;
    }

    // Okay if we got here.
    return true;
}

bool cols() {

    // Loops through columns.
    for (int j=0; j<SIZE; j++) {

        // Count stars on col j.
        int cnt = 0;
        for (int i=0; i<SIZE; i++)
            if (res[i][j] == '*')
                cnt++;

        // This is bad.
        if (cnt != MAGIC) return false;
    }

    // Okay if we got here.
    return true;
}

bool regions() {

    // Set up frequency vector for regions.
    vector<int> freq(SIZE, 0);

    for (int i=0; i<SIZE; i++) {
        for (int j=0; j<SIZE; j++) {

            // These don't count.
            if (res[i][j] != '*') continue;

            // Update frequency of this region.
            freq[grid[i][j]]++;
        }
    }

    // Must always have frequency of magic value.
    for (int i=0; i<SIZE; i++)
        if (freq[i] != MAGIC)
            return false;

    // We're good.
    return true;
}

// Returns true iff adjacency rule is met.
bool adj() {

    // Try every square, every direction.
    for (int i=0; i<SIZE; i++) {
        for (int j=0; j<SIZE; j++) {
            for (int dir=0; dir<DX.size(); dir++) {

                // Nothing to compare so skip it.
                if (!inbounds(i+DX[dir], j+DY[dir])) continue;

                // Can't both be stars.
                if (res[i][j] != '*') continue;

                // Oops, adjacent.
                if (res[i+DX[dir]][j+DY[dir]] == '*') return false;
            }
        }
    }

    // No adjacent bombs so we pass the adjacency test.
    return true;
}

// Returns true iff (x, y) is inbounds.
bool inbounds(int x, int y) {
    return x>=0 && x <SIZE && y>=0 && y<SIZE;
}
