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

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

d = A("d")
i = B("i")
h = B("h")
l = B("l")
k = A("k")
f = A("f")
j = A("j")

d.q = i
i.x = h
h.x = i
l.x = h
k.q = i
f.q = h
j.q = i
assert d.q.x.x.x.x.txt == "
class A:
    def __init__(self, txt: str):
        self.q: B = None
        self.txt = txt

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

d = A("d")
i = B("i")
h = B("h")
l = B("l")
k = A("k")
f = A("f")
j = A("j")

d.q = i
i.x = h
h.x = i
l.x = h
k.q = i
f.q = h
j.q = i
assert d.q.x.x.x.x.txt == "i"