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

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

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

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

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

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

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

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

j.q = i
k.x = j
b.x = i
b.u = k
i.x = d
i.u = k
d.x = i
d.u = k
assert i.u.x.q.u.txt == "k"