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

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

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

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

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

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

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

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

d.o = n
e.p = i
e.y = d
g.x = i
f.o = n
a.o = c
n.p = g
n.y = d
m.o = e
i.x = g
c.p = g
c.y = a
assert g.x.x.x.x.x.x.txt == "g"