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

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

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

g.z = m
j.y = k
m.z = i
i.z = h
n.z = h
a.z = m
k.y = j
h.z = i
assert g.z.z.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.y: B = None
        self.txt = txt

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

g.z = m
j.y = k
m.z = i
i.z = h
n.z = h
a.z = m
k.y = j
h.z = i
assert g.z.z.z.z.z.z.z.z.txt == "i"