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

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

b = A("b")
a = B("a")
m = B("m")
c = B("c")
g = A("g")
f = A("f")

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

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

b = A("b")
a = B("a")
m = B("m")
c = B("c")
g = A("g")
f = A("f")

b.y = c
b.o = c
a.x = m
a.z = b
m.x = a
m.z = f
c.x = m
c.z = f
g.y = m
g.o = c
f.y = m
f.o = c
assert b.y.z.o.z.y.x.txt == "a"