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

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

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

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

d.s = a
d.x = a
a.q = d
a.w = m
m.s = d
assert a.w.s.x.txt == "
class A:
    def __init__(self, txt: str):
        self.s: B = None
        self.x: B = None
        self.txt = txt

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

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

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

d.s = a
d.x = a
a.q = d
a.w = m
m.s = d
assert a.w.s.x.txt == "a"