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.t: A = None
        self.txt = txt

e = A("e")
j = B("j")
d = A("d")
h = A("h")
b = A("b")
i = B("i")
n = A("n")
f = B("f")
g = A("g")

e.z = h
j.w = i
j.t = d
d.z = g
h.z = g
b.z = n
i.w = f
i.t = g
n.z = e
f.w = i
f.t = d
g.z = h
assert d.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.t: A = None
        self.txt = txt

e = A("e")
j = B("j")
d = A("d")
h = A("h")
b = A("b")
i = B("i")
n = A("n")
f = B("f")
g = A("g")

e.z = h
j.w = i
j.t = d
d.z = g
h.z = g
b.z = n
i.w = f
i.t = g
n.z = e
f.w = i
f.t = d
g.z = h
assert d.z.z.z.z.z.z.txt == "h"