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

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

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

a = A("a")
n = B("n")
j = C("j")
i = C("i")

a.p = j
n.u = j
n.v = i
j.q = a
i.q = a
assert n.u.q.p.txt == "
class A:
    def __init__(self, txt: str):
        self.p: C = None
        self.txt = txt

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

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

a = A("a")
n = B("n")
j = C("j")
i = C("i")

a.p = j
n.u = j
n.v = i
j.q = a
i.q = a
assert n.u.q.p.txt == "j"