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

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

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

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

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

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

c.t = m
c.w = f
j.u = d
f.u = m
m.t = a
m.w = j
d.t = a
d.w = f
a.t = d
a.w = f
assert f.u.t.w.u.w.u.txt == "d"