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

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

e = A("e")
a = B("a")
i = B("i")
m = B("m")
d = B("d")
j = A("j")
l = A("l")
b = B("b")

e.t = i
e.w = j
a.r = e
i.r = j
m.r = e
d.r = j
j.t = b
j.w = l
l.t = m
l.w = e
b.r = l
assert e.w.t.r.t.r.txt == "
class A:
    def __init__(self, txt: str):
        self.t: B = None
        self.w: A = None
        self.txt = txt

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

e = A("e")
a = B("a")
i = B("i")
m = B("m")
d = B("d")
j = A("j")
l = A("l")
b = B("b")

e.t = i
e.w = j
a.r = e
i.r = j
m.r = e
d.r = j
j.t = b
j.w = l
l.t = m
l.w = e
b.r = l
assert e.w.t.r.t.r.txt == "e"