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

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

h = A("h")
j = B("j")
g = B("g")
c = B("c")
d = B("d")
a = B("a")

h.q = j
j.z = c
g.z = j
c.z = a
d.z = g
a.z = g
assert j.z.z.z.z.txt == "
class A:
    def __init__(self, txt: str):
        self.q: B = None
        self.txt = txt

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

h = A("h")
j = B("j")
g = B("g")
c = B("c")
d = B("d")
a = B("a")

h.q = j
j.z = c
g.z = j
c.z = a
d.z = g
a.z = g
assert j.z.z.z.z.txt == "j"