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

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

h = A("h")
g = B("g")
n = A("n")
e = A("e")
a = B("a")
l = A("l")
f = B("f")
j = A("j")

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

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

h = A("h")
g = B("g")
n = A("n")
e = A("e")
a = B("a")
l = A("l")
f = B("f")
j = A("j")

h.w = g
h.x = l
g.y = f
g.x = a
n.w = g
n.x = l
e.w = g
e.x = h
a.y = f
a.x = g
l.w = f
l.x = h
f.y = a
f.x = g
j.w = f
j.x = n
assert f.y.y.x.txt == "g"