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

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

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

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

l = A("l")
n = B("n")
c = C("c")
d = D("d")
a = C("a")
f = A("f")
m = C("m")
g = B("g")
b = D("b")
j = A("j")

l.o = m
l.x = j
n.p = a
n.o = g
c.o = l
c.q = g
d.y = f
a.o = j
a.q = n
f.o = c
f.x = l
m.o = j
m.q = g
g.p = a
g.o = n
b.y = j
j.o = m
j.x = f
assert n.p.o.o.o.o.q.txt == "
class A:
    def __init__(self, txt: str):
        self.o: C = None
        self.x: A = None
        self.txt = txt

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

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

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

l = A("l")
n = B("n")
c = C("c")
d = D("d")
a = C("a")
f = A("f")
m = C("m")
g = B("g")
b = D("b")
j = A("j")

l.o = m
l.x = j
n.p = a
n.o = g
c.o = l
c.q = g
d.y = f
a.o = j
a.q = n
f.o = c
f.x = l
m.o = j
m.q = g
g.p = a
g.o = n
b.y = j
j.o = m
j.x = f
assert n.p.o.o.o.o.q.txt == "g"