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

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

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

k = A("k")
m = B("m")
d = C("d")
b = B("b")

k.w = d
m.w = k
d.t = b
d.v = k
d.q = m
b.w = k
assert d.q.w.w.q.txt == "
class A:
    def __init__(self, txt: str):
        self.w: C = None
        self.txt = txt

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

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

k = A("k")
m = B("m")
d = C("d")
b = B("b")

k.w = d
m.w = k
d.t = b
d.v = k
d.q = m
b.w = k
assert d.q.w.w.q.txt == "m"