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

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

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

c = A("c")
b = B("b")
e = C("e")
n = A("n")
f = A("f")

c.x = b
c.w = f
b.p = e
b.q = e
e.x = f
e.u = n
e.r = b
n.x = b
n.w = f
f.x = b
f.w = c
assert f.x.q.r.p.u.txt == "
class A:
    def __init__(self, txt: str):
        self.x: B = None
        self.w: A = None
        self.txt = txt

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

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

c = A("c")
b = B("b")
e = C("e")
n = A("n")
f = A("f")

c.x = b
c.w = f
b.p = e
b.q = e
e.x = f
e.u = n
e.r = b
n.x = b
n.w = f
f.x = b
f.w = c
assert f.x.q.r.p.u.txt == "n"