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

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

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

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

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

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

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

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

n.z = b
j.o = n
j.v = g
j.u = g
g.p = b
b.z = n
assert j.v.p.z.txt == "n"