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

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

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

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

c = A("c")
a = B("a")
i = C("i")
f = D("f")
l = D("l")
n = A("n")
g = B("g")
m = C("m")

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

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

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

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

c = A("c")
a = B("a")
i = C("i")
f = D("f")
l = D("l")
n = A("n")
g = B("g")
m = C("m")

c.p = g
a.r = n
a.y = c
a.p = m
a.w = g
i.x = c
i.q = c
i.y = m
i.o = a
f.p = n
l.p = c
n.p = g
g.r = n
g.y = c
g.p = i
g.w = a
m.x = n
m.y = i
m.o = a
m.q = c
assert f.p.p.r.p.w.w.r.txt == "n"