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

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

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

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

g.r = i
c.o = n
n.o = c
n.y = d
i.r = g
d.o = c
d.y = n
a.r = e
e.r = g
assert c.o.y.y.o.o.txt == "
class A:
    def __init__(self, txt: str):
        self.r: A = None
        self.txt = txt

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

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

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

g.r = i
c.o = n
n.o = c
n.y = d
i.r = g
d.o = c
d.y = n
a.r = e
e.r = g
assert c.o.y.y.o.o.txt == "n"