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

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

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

k.z = h
b.t = g
d.t = k
g.z = k
h.z = g
j.z = g
a.t = h
assert j.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.t: A = None
        self.txt = txt

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

k.z = h
b.t = g
d.t = k
g.z = k
h.z = g
j.z = g
a.t = h
assert j.z.z.z.z.z.z.z.txt == "g"