class A:
    def __init__(self, txt: str):
        self.s: C = None
        self.txt = txt

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

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

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

d.s = b
l.t = b
l.q = m
m.p = l
b.p = l
assert b.p.t.p.txt == "
class A:
    def __init__(self, txt: str):
        self.s: C = None
        self.txt = txt

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

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

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

d.s = b
l.t = b
l.q = m
m.p = l
b.p = l
assert b.p.t.p.txt == "l"