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

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

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

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

b = A("b")
g = B("g")
a = C("a")
f = D("f")
h = C("h")
n = A("n")

b.s = f
b.w = f
g.s = b
g.o = a
a.p = b
a.t = n
a.q = n
a.y = h
f.u = g
f.x = g
h.p = b
h.t = b
h.y = a
h.q = n
n.s = f
n.w = f
assert f.x.o.p.w.txt == "
class A:
    def __init__(self, txt: str):
        self.s: D = None
        self.w: D = None
        self.txt = txt

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

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

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

b = A("b")
g = B("g")
a = C("a")
f = D("f")
h = C("h")
n = A("n")

b.s = f
b.w = f
g.s = b
g.o = a
a.p = b
a.t = n
a.q = n
a.y = h
f.u = g
f.x = g
h.p = b
h.t = b
h.y = a
h.q = n
n.s = f
n.w = f
assert f.x.o.p.w.txt == "f"