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

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

h = A("h")
e = B("e")
a = A("a")
g = B("g")
b = B("b")
m = A("m")
k = B("k")
d = A("d")

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

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

h = A("h")
e = B("e")
a = A("a")
g = B("g")
b = B("b")
m = A("m")
k = B("k")
d = A("d")

h.z = g
e.o = k
a.z = g
g.o = e
b.o = g
m.z = b
k.o = b
d.z = k
assert e.o.o.o.o.txt == "e"