s := edit3.text; for i := 0 to length(s) - 1 do for j := 0 to length(s) - 1 do StringGrid1.Cells[i, j] := StringGrid3.Cells[i, StrtoInt(s[j+1])];