#include <iostream>
#include <algorithm>
#include <cmath>

using namespace std;
int a[10][10];
int b[10][10];
int main() {
    for (int i = 0; i < 4; i++) {
        for (int j = 0; j < 5; j++) {
            cin >> a[i][j];
        }
    }
    int flag  = 0;
    for (int i = 0; i < 5; i++) {
        int max1 = -99999, max2 = -999999;
        int pos1, pos2;
        for (int j = 0; j < 4; j++) {
            if (max1 < a[j][i]) {
                max1 = a[j][i];
                pos1 = j;
            }
        }
        for (int j = 0; j < 4; j++) {
            if (max2 <= a[j][i] && j!=pos1) {
                max2 = a[j][i];
                pos2 = j;
            }
        }
        if(pos1>pos2)swap(max1,max2);
        a[0][i] = max1;
        a[1][i] = max2;
    }
    for(int i=0;i<2;i++)
    {
        for(int j=0;j<5;j++)
        {
            cout<<a[i][j]<<" ";
        }
        cout<<endl;
    }
}
// 64 位输出请用 printf("%lld")