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

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

a.z = g
i.y = n
d.y = k
j.y = k
n.y = i
h.y = j
k.y = h
g.z = a
assert k.y.y.y.y.y.y.y.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

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

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