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

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

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

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

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

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

e.t = h
e.w = f
f.r = h
f.t = l
h.r = f
h.t = g
g.t = h
g.w = h
l.t = f
l.w = f
a.t = f
a.w = f
assert l.t.t.t.r.txt == "h"