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.w: A = None
        self.txt = txt

e = A("e")
k = B("k")
a = B("a")
g = B("g")
i = B("i")
c = A("c")
b = A("b")
f = A("f")

e.t = f
e.w = a
k.w = e
a.w = b
g.w = f
i.w = f
c.t = f
c.w = g
b.t = e
b.w = a
f.t = c
f.w = g
assert g.w.t.w.w.t.t.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.w: A = None
        self.txt = txt

e = A("e")
k = B("k")
a = B("a")
g = B("g")
i = B("i")
c = A("c")
b = A("b")
f = A("f")

e.t = f
e.w = a
k.w = e
a.w = b
g.w = f
i.w = f
c.t = f
c.w = g
b.t = e
b.w = a
f.t = c
f.w = g
assert g.w.t.w.w.t.t.txt == "f"