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

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

h = A("h")
a = B("a")
j = B("j")
e = A("e")
b = A("b")
f = B("f")
n = A("n")
d = A("d")

h.y = j
h.x = j
a.t = h
a.w = j
j.t = b
j.w = a
e.y = f
e.x = a
b.y = a
b.x = j
f.t = n
f.w = a
n.y = j
n.x = a
d.y = a
d.x = j
assert e.y.w.w.w.t.x.w.txt == "
class A:
    def __init__(self, txt: str):
        self.y: B = None
        self.x: B = None
        self.txt = txt

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

h = A("h")
a = B("a")
j = B("j")
e = A("e")
b = A("b")
f = B("f")
n = A("n")
d = A("d")

h.y = j
h.x = j
a.t = h
a.w = j
j.t = b
j.w = a
e.y = f
e.x = a
b.y = a
b.x = j
f.t = n
f.w = a
n.y = j
n.x = a
d.y = a
d.x = j
assert e.y.w.w.w.t.x.w.txt == "a"