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

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

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

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

d.u = m
b.z = j
b.p = d
m.q = j
j.u = m
assert j.u.q.u.q.txt == "
class A:
    def __init__(self, txt: str):
        self.u: C = None
        self.txt = txt

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

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

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

d.u = m
b.z = j
b.p = d
m.q = j
j.u = m
assert j.u.q.u.q.txt == "j"