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

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

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

n = A("n")
c = B("c")
a = C("a")
i = B("i")
f = B("f")

n.p = i
n.q = a
c.w = a
c.y = a
a.u = c
a.x = n
i.w = a
i.y = a
f.w = a
f.y = a
assert n.q.x.p.txt == "
class A:
    def __init__(self, txt: str):
        self.p: B = None
        self.q: C = None
        self.txt = txt

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

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

n = A("n")
c = B("c")
a = C("a")
i = B("i")
f = B("f")

n.p = i
n.q = a
c.w = a
c.y = a
a.u = c
a.x = n
i.w = a
i.y = a
f.w = a
f.y = a
assert n.q.x.p.txt == "i"