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

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

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

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

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

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

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