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

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

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

d = A("d")
i = B("i")
a = C("a")

d.p = a
d.q = a
i.p = d
i.q = a
a.s = i
a.w = i
assert i.p.q.w.txt == "
class A:
    def __init__(self, txt: str):
        self.p: C = None
        self.q: C = None
        self.txt = txt

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

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

d = A("d")
i = B("i")
a = C("a")

d.p = a
d.q = a
i.p = d
i.q = a
a.s = i
a.w = i
assert i.p.q.w.txt == "i"