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

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

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

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

n = A("n")
j = B("j")
g = C("g")
b = D("b")
i = A("i")
l = A("l")
d = C("d")
m = D("m")

n.o = i
j.x = m
g.q = d
g.p = j
g.w = b
b.o = g
i.o = l
l.o = i
d.q = g
d.p = j
d.w = m
m.o = g
assert d.w.o.q.w.o.q.q.p.txt == "
class A:
    def __init__(self, txt: str):
        self.o: A = None
        self.txt = txt

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

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

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

n = A("n")
j = B("j")
g = C("g")
b = D("b")
i = A("i")
l = A("l")
d = C("d")
m = D("m")

n.o = i
j.x = m
g.q = d
g.p = j
g.w = b
b.o = g
i.o = l
l.o = i
d.q = g
d.p = j
d.w = m
m.o = g
assert d.w.o.q.w.o.q.q.p.txt == "j"