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

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

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

e = A("e")
d = B("d")
c = C("c")

e.q = c
e.x = d
d.x = c
c.w = d
c.r = e
assert c.w.x.w.txt == "
class A:
    def __init__(self, txt: str):
        self.q: C = None
        self.x: B = None
        self.txt = txt

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

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

e = A("e")
d = B("d")
c = C("c")

e.q = c
e.x = d
d.x = c
c.w = d
c.r = e
assert c.w.x.w.txt == "d"