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.txt = txt

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

a = A("a")
k = B("k")
b = C("b")

a.s = k
a.x = k
k.q = a
b.p = k
b.v = k
b.r = a
assert k.q.x.q.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.txt = txt

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

a = A("a")
k = B("k")
b = C("b")

a.s = k
a.x = k
k.q = a
b.p = k
b.v = k
b.r = a
assert k.q.x.q.txt == "a"