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

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

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

a = A("a")
f = B("f")
e = C("e")

a.x = e
a.p = e
f.p = e
f.r = e
e.q = f
assert a.x.q.r.txt == "
class A:
    def __init__(self, txt: str):
        self.x: C = None
        self.p: C = None
        self.txt = txt

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

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

a = A("a")
f = B("f")
e = C("e")

a.x = e
a.p = e
f.p = e
f.r = e
e.q = f
assert a.x.q.r.txt == "e"