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

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

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

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

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

b.o = h
f.t = a
f.o = i
f.w = j
n.w = f
n.r = f
a.y = f
a.w = f
a.s = b
h.y = f
h.w = f
h.s = b
i.w = f
i.r = f
j.o = a
assert a.s.o.s.txt == "
class A:
    def __init__(self, txt: str):
        self.o: D = None
        self.txt = txt

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

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

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

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

b.o = h
f.t = a
f.o = i
f.w = j
n.w = f
n.r = f
a.y = f
a.w = f
a.s = b
h.y = f
h.w = f
h.s = b
i.w = f
i.r = f
j.o = a
assert a.s.o.s.txt == "b"