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

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

f = A("f")
e = B("e")
l = B("l")
a = B("a")
j = A("j")
m = B("m")

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

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

f = A("f")
e = B("e")
l = B("l")
a = B("a")
j = A("j")
m = B("m")

f.r = l
e.w = a
e.t = a
l.w = m
l.t = e
a.w = e
a.t = m
j.r = a
m.w = l
m.t = e
assert f.r.t.t.t.w.t.txt == "e"