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

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

d = A("d")
g = B("g")
a = B("a")
i = B("i")
j = B("j")

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

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

d = A("d")
g = B("g")
a = B("a")
i = B("i")
j = B("j")

d.q = g
g.y = i
a.y = j
i.y = a
j.y = a
assert j.y.y.y.txt == "a"