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

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

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

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

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

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

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

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

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

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

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