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

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

k = A("k")
a = B("a")
m = B("m")
f = A("f")
h = A("h")
b = B("b")
j = B("j")
e = B("e")

k.x = a
k.w = j
a.s = h
m.s = k
f.x = j
f.w = a
h.x = e
h.w = m
b.s = h
j.s = h
e.s = h
assert h.x.s.w.s.x.s.x.s.txt == "
class A:
    def __init__(self, txt: str):
        self.x: B = None
        self.w: B = None
        self.txt = txt

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

k = A("k")
a = B("a")
m = B("m")
f = A("f")
h = A("h")
b = B("b")
j = B("j")
e = B("e")

k.x = a
k.w = j
a.s = h
m.s = k
f.x = j
f.w = a
h.x = e
h.w = m
b.s = h
j.s = h
e.s = h
assert h.x.s.w.s.x.s.x.s.txt == "h"