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

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

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

j = A("j")
k = B("k")
n = C("n")
c = B("c")

j.q = n
j.p = n
k.u = n
k.r = n
k.x = j
n.x = k
c.u = n
c.r = n
c.x = j
assert c.x.q.x.x.txt == "
class A:
    def __init__(self, txt: str):
        self.q: C = None
        self.p: C = None
        self.txt = txt

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

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

j = A("j")
k = B("k")
n = C("n")
c = B("c")

j.q = n
j.p = n
k.u = n
k.r = n
k.x = j
n.x = k
c.u = n
c.r = n
c.x = j
assert c.x.q.x.x.txt == "j"