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

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

m = A("m")
n = B("n")
h = A("h")
k = B("k")
f = B("f")
g = B("g")
i = A("i")

m.y = n
n.z = k
n.o = h
h.y = k
k.z = f
k.o = i
f.z = k
f.o = i
g.z = n
g.o = h
i.y = g
assert g.z.z.z.z.o.y.txt == "
class A:
    def __init__(self, txt: str):
        self.y: B = None
        self.txt = txt

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

m = A("m")
n = B("n")
h = A("h")
k = B("k")
f = B("f")
g = B("g")
i = A("i")

m.y = n
n.z = k
n.o = h
h.y = k
k.z = f
k.o = i
f.z = k
f.o = i
g.z = n
g.o = h
i.y = g
assert g.z.z.z.z.o.y.txt == "g"