class A:
    def __init__(self, txt: str):
        self.o: A = None
        self.z: A = None
        self.txt = txt

class B:
    def __init__(self, txt: str):
        self.w: A = None
        self.txt = txt

m = A("m")
a = B("a")
l = A("l")
k = B("k")
h = A("h")
g = A("g")
c = B("c")
f = A("f")

m.o = l
m.z = g
a.w = g
l.o = g
l.z = h
k.w = f
h.o = g
h.z = m
g.o = l
g.z = f
c.w = h
f.o = h
f.z = l
assert m.z.o.z.txt == "
class A:
    def __init__(self, txt: str):
        self.o: A = None
        self.z: A = None
        self.txt = txt

class B:
    def __init__(self, txt: str):
        self.w: A = None
        self.txt = txt

m = A("m")
a = B("a")
l = A("l")
k = B("k")
h = A("h")
g = A("g")
c = B("c")
f = A("f")

m.o = l
m.z = g
a.w = g
l.o = g
l.z = h
k.w = f
h.o = g
h.z = m
g.o = l
g.z = f
c.w = h
f.o = h
f.z = l
assert m.z.o.z.txt == "h"