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

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

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

k = A("k")
j = B("j")
c = C("c")
i = B("i")
d = C("d")

k.u = c
j.q = i
j.t = k
j.u = k
c.w = k
c.u = d
i.q = j
i.t = k
i.u = k
d.w = k
d.u = c
assert j.q.q.u.txt == "
class A:
    def __init__(self, txt: str):
        self.u: C = None
        self.txt = txt

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

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

k = A("k")
j = B("j")
c = C("c")
i = B("i")
d = C("d")

k.u = c
j.q = i
j.t = k
j.u = k
c.w = k
c.u = d
i.q = j
i.t = k
i.u = k
d.w = k
d.u = c
assert j.q.q.u.txt == "k"