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

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

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

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

d.r = l
g.z = n
g.r = l
g.o = d
n.u = d
l.z = n
l.r = g
l.o = d
assert l.o.r.o.txt == "
class A:
    def __init__(self, txt: str):
        self.r: B = None
        self.txt = txt

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

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

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

d.r = l
g.z = n
g.r = l
g.o = d
n.u = d
l.z = n
l.r = g
l.o = d
assert l.o.r.o.txt == "d"