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

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

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

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

m = A("m")
a = B("a")
n = C("n")
j = D("j")
d = B("d")
i = B("i")
f = C("f")
b = D("b")

m.w = j
m.p = n
m.o = f
a.x = j
a.p = f
a.q = d
n.y = j
n.p = m
n.w = m
n.r = a
j.z = m
j.x = d
d.x = j
d.p = f
d.q = a
i.x = j
i.p = f
i.q = d
f.y = b
f.p = m
f.w = m
f.r = a
b.z = m
b.x = a
assert b.x.q.x.x.q.p.y.txt == "
class A:
    def __init__(self, txt: str):
        self.w: D = None
        self.p: C = None
        self.o: C = None
        self.txt = txt

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

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

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

m = A("m")
a = B("a")
n = C("n")
j = D("j")
d = B("d")
i = B("i")
f = C("f")
b = D("b")

m.w = j
m.p = n
m.o = f
a.x = j
a.p = f
a.q = d
n.y = j
n.p = m
n.w = m
n.r = a
j.z = m
j.x = d
d.x = j
d.p = f
d.q = a
i.x = j
i.p = f
i.q = d
f.y = b
f.p = m
f.w = m
f.r = a
b.z = m
b.x = a
assert b.x.q.x.x.q.p.y.txt == "b"