/************************************************
Grundlegende Algorithmen mit Java,
http://algorithmen-und-problemloesungen.de/
Copyright @2007-2008 by Doina Logofatu
************************************************/

import java.io.*;
import java.util.*;

public class P13Sudoku {
  private static final String FileInputName = "sudoku.in";
  private static final String FileOutputName = "sudoku.out";
  private static final char V = '*';
  private static final int N = 3;
  private static final int DIM = N*N;
  private BitSet sl[];
  private BitSet sc[];
  private BitSet[][] sb;
  private int[][] v;
  private static int anzahl = 0;

  P13Sudoku() {
    this.sl = new BitSet[DIM];
    this.sc = new BitSet[DIM];
    for (int i = 0; i < DIM; i++) {
      this.sl[i] = new BitSet();
      this.sc[i] = new BitSet();
    }
    this.sb = new BitSet[N][N];
    for (int i = 0; i < N; i++)
      for (int j = 0; j < N; j++)
        sb[i][j] = new BitSet();
    this.v = new int[DIM][DIM];
  }

  boolean set(int l, int c, int value)
  {
    if (!sl[l].get(value) && 
      !sc[c].get(value) && 
      !sb[l / N][c / N].get(value))
    {
      sl[l].set(value);
      sc[c].set(value);
      sb[l / N][c / N].set(value);
      v[l][c] = value;
      return true;
    }
    else
      return false;   
  }
  
  void unset(int l, int c, int value)
  {
    sl[l].clear(value);
    sc[c].clear(value);
    sb[l/N][c/N].clear(value);
    v[l][c] = 0;
  }
  
  void run(Scanner scanner, PrintStream out) {
    int l = 0, c = 0;
    while (scanner.hasNext() && l < DIM) {
      String s = scanner.next();
      for (int i = 0; i < s.length(); i++) {
        char ch = s.charAt(i);
        if (Character.isDigit(ch) || ch == V) {
          if (ch != V) {
            if (!set(l, c, Character.digit(ch, 10)))
              return;
          }
          if (DIM == ++c) {
            l++;
            c = 0;
          }
        }
      }
    }
    back(0, -1, out);
  }

  private void writeSolution(PrintStream out) 
  {
    for (int l=0; l < DIM; l++)
    {
    out.print(v[l][0]);
    for (int c=1; c < DIM; c++)
    {
      out.print(' ');
      out.print(v[l][c]);
    }
    out.println();
    }     
    out.println();
  }

  private void back(int l, int c, PrintStream out) {
    do {
    c++;
    if (c == DIM) {
      c = 0;
      l++;
      if (l == DIM) {
        writeSolution(out);
        return;
      }
    }
    }
    while (v[l][c] != 0);
    for (int value = 1; value <= DIM; ++value) {
      if (set(l, c, value)) {
        back(l, c, out);
        unset(l, c, value);
      }
    }
  }

  public static void main(String[] args) throws IOException {
    Scanner scanner = null;
    PrintStream out = null;
    try {
      out = new PrintStream(new File(FileOutputName));
      scanner = new Scanner(new File(FileInputName));
      new P13Sudoku().run(scanner, out);
    } finally {
      if (scanner != null) {
        scanner.close();
      }
      if (out != null) {
          System.out.print(anzahl);
        out.close();
      }
    }
  }
}


/// A second Version ///
/*
import java.io.*;
import java.util.*;

public class P13Sudoku {
  private static final String FileInputName = "sudoku.in";
  private static final String FileOutputName = "sudoku.out";
  private static final char V = '*';
  private static final short DIM = 9;
  private static final short NR = 3;
  private Set<Integer> sl[];
  private Set<Integer> sc[];
  private Set<Integer>[][] sb;
  private List<Integer> t;
  private List<TPair> pos;

  @SuppressWarnings("unchecked")
  P13Sudoku() {
    this.sl = new Set[DIM];
    this.sc = new Set[DIM];
    for (int i = 0; i < DIM; i++) {
      this.sl[i] = new HashSet<Integer>();
      this.sc[i] = new HashSet<Integer>();
    }
    int dim_nr = DIM / NR;
    this.sb = new Set[dim_nr][dim_nr];
    for (int i = 0; i < dim_nr; i++)
      for (int j = 0; j < dim_nr; j++)
        sb[i][j] = new HashSet<Integer>();
    this.t = new ArrayList<Integer>();
    this.pos = new ArrayList<TPair>();
  }

  void run(Scanner scanner, PrintStream out) {
    int l = 0, c = 0;
    while (scanner.hasNext() && l < DIM) {
      String s = scanner.next();
      for (int i = 0; i < s.length(); i++) {
        char ch = s.charAt(i);
        if (Character.isDigit(ch) || ch == V) {
          if (ch == V)
            pos.add(new TPair(l, c));
          else {
            int digit = Character.digit(ch, 10);
            sl[l].add(digit);
            sc[c].add(digit);
            sb[l / NR][c / NR].add(digit);
            t.add(digit);
          }
          if (DIM == ++c) {
            l++;
            c = 0;
          }
        }
      }
    }
    List<Integer> v = new ArrayList<Integer>();
    for (int i = 0; i < pos.size(); i++)
      v.add(0);
    back(0, v, out);
  }

  private boolean isCandidat(List<Integer> v, int k) {
    TPair posK = pos.get(k);
    int ll = posK.getFirst();
    int cc = posK.getSecond();
    return !sl[ll].contains(v.get(k)) && !sc[cc].contains(v.get(k))
        && !sb[ll / NR][cc / NR].contains(v.get(k));
  }

  private void writeSolution(List<Integer> v, PrintStream out) {
    int k = 0;
    int j = 0;
    int ll = 0;
    int cc = 0;
    while (ll < DIM) {
      TPair posK = pos.get(k);
      if (posK.getFirst() == ll && posK.getSecond() == cc) {
        out.print(v.get((k++)));
        out.print(' ');
      } else {
        out.print(t.get(j++));
        out.print(' ');
      }
      if (++cc == DIM) {
        ll++;
        cc = 0;
        out.println();
      }
    }
    out.println();
  }

  private void back(int k, List<Integer> v, PrintStream out) {
    if (k == pos.size()) {
      writeSolution(v, out);
      return;
    }
    for (int i = 1; i <= DIM; ++i) {
      v.set(k, i);
      if (isCandidat(v, k)) {
        TPair posK = pos.get(k);
        sl[posK.getFirst()].add(v.get(k));
        sc[posK.getSecond()].add(v.get(k));
        sb[posK.getFirst() / NR][posK.getSecond() / NR].add(v.get(k));
        back(k + 1, v, out);
        sl[posK.getFirst()].remove(v.get(k));
        sc[posK.getSecond()].remove(v.get(k));
        sb[posK.getFirst() / NR][posK.getSecond() / NR].remove(v.get(k));
      }
    }
  }

  @SuppressWarnings("unchecked")
  public static void main(String[] args) throws IOException {
    Scanner scanner = null;
    PrintStream out = null;
    try {
      out = new PrintStream(new File(FileOutputName));
      scanner = new Scanner(new File(FileInputName));
      new P13Sudoku().run(scanner, out);
    } finally {
      if (scanner != null) {
        scanner.close();
      }
      if (out != null) {
        out.close();
      }
    }
  }
}

class TPair {
  private int first;

  private int second;

  TPair(int first, int second) {
    this.first = first;
    this.second = second;
  }

  int getFirst() {
    return first;
  }

  int getSecond() {
    return second;
  }
}

*/

