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

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

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

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

k.w = b
k.q = b
a.r = k
d.z = b
d.u = a
b.w = k
b.q = k
assert b.w.w.q.txt == "
class A:
    def __init__(self, txt: str):
        self.w: A = None
        self.q: A = None
        self.txt = txt

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

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

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

k.w = b
k.q = b
a.r = k
d.z = b
d.u = a
b.w = k
b.q = k
assert b.w.w.q.txt == "k"