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

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

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

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

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

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

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