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

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

f = A("f")
e = B("e")
i = B("i")
j = A("j")
g = A("g")
a = A("a")
h = A("h")
c = B("c")

f.z = a
e.w = i
e.s = c
i.w = e
i.s = e
j.z = f
g.z = h
a.z = h
h.z = g
c.w = i
c.s = i
assert h.z.z.z.z.z.z.txt == "
class A:
    def __init__(self, txt: str):
        self.z: A = None
        self.txt = txt

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

f = A("f")
e = B("e")
i = B("i")
j = A("j")
g = A("g")
a = A("a")
h = A("h")
c = B("c")

f.z = a
e.w = i
e.s = c
i.w = e
i.s = e
j.z = f
g.z = h
a.z = h
h.z = g
c.w = i
c.s = i
assert h.z.z.z.z.z.z.txt == "h"