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

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

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

b = A("b")
d = B("d")
l = C("l")

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

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

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

b = A("b")
d = B("d")
l = C("l")

b.p = d
d.u = b
d.q = b
l.p = d
l.t = d
l.w = b
assert d.q.p.u.txt == "b"