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

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

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

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

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

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

g.z = e
g.x = d
k.r = d
k.w = g
d.z = m
d.x = h
h.z = e
h.x = d
m.r = h
m.w = g
e.r = h
e.w = h
assert h.x.x.x.z.w.z.txt == "e"