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

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

m = A("m")
e = B("e")
g = A("g")
d = B("d")
f = A("f")
a = B("a")

m.o = d
e.z = f
e.y = f
g.o = a
d.z = f
d.y = m
f.o = d
a.z = f
a.y = g
assert a.z.o.y.txt == "
class A:
    def __init__(self, txt: str):
        self.o: B = None
        self.txt = txt

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

m = A("m")
e = B("e")
g = A("g")
d = B("d")
f = A("f")
a = B("a")

m.o = d
e.z = f
e.y = f
g.o = a
d.z = f
d.y = m
f.o = d
a.z = f
a.y = g
assert a.z.o.y.txt == "m"