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

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

f = A("f")
j = B("j")
d = A("d")
b = B("b")

f.q = b
j.u = b
j.p = b
d.q = b
b.u = j
b.p = j
assert d.q.u.u.txt == "
class A:
    def __init__(self, txt: str):
        self.q: B = None
        self.txt = txt

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

f = A("f")
j = B("j")
d = A("d")
b = B("b")

f.q = b
j.u = b
j.p = b
d.q = b
b.u = j
b.p = j
assert d.q.u.u.txt == "b"