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

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

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

g = A("g")
c = B("c")
n = C("n")
b = A("b")

g.z = b
c.x = n
c.w = n
c.o = b
n.u = c
n.p = c
b.z = g
assert c.o.z.z.txt == "
class A:
    def __init__(self, txt: str):
        self.z: A = None
        self.txt = txt

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

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

g = A("g")
c = B("c")
n = C("n")
b = A("b")

g.z = b
c.x = n
c.w = n
c.o = b
n.u = c
n.p = c
b.z = g
assert c.o.z.z.txt == "b"