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

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

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

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

n = A("n")
h = B("h")
c = C("c")
k = D("k")
b = D("b")
d = C("d")
g = C("g")
i = B("i")
l = C("l")

n.o = b
n.w = k
h.p = g
h.w = n
h.r = b
c.t = i
c.q = n
k.p = n
k.w = n
b.p = n
b.w = n
d.t = h
d.q = n
g.t = h
g.q = n
i.p = d
i.w = n
i.r = b
l.t = h
l.q = n
assert l.q.w.w.txt == "
class A:
    def __init__(self, txt: str):
        self.o: D = None
        self.w: D = None
        self.txt = txt

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

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

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

n = A("n")
h = B("h")
c = C("c")
k = D("k")
b = D("b")
d = C("d")
g = C("g")
i = B("i")
l = C("l")

n.o = b
n.w = k
h.p = g
h.w = n
h.r = b
c.t = i
c.q = n
k.p = n
k.w = n
b.p = n
b.w = n
d.t = h
d.q = n
g.t = h
g.q = n
i.p = d
i.w = n
i.r = b
l.t = h
l.q = n
assert l.q.w.w.txt == "n"