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

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

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

n = A("n")
i = B("i")
g = C("g")
l = C("l")
c = A("c")
d = B("d")

n.o = l
i.p = d
g.o = d
g.z = i
g.r = n
l.o = i
l.z = d
l.r = c
c.o = l
d.p = i
assert n.o.r.o.txt == "
class A:
    def __init__(self, txt: str):
        self.o: C = None
        self.txt = txt

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

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

n = A("n")
i = B("i")
g = C("g")
l = C("l")
c = A("c")
d = B("d")

n.o = l
i.p = d
g.o = d
g.z = i
g.r = n
l.o = i
l.z = d
l.r = c
c.o = l
d.p = i
assert n.o.r.o.txt == "l"