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

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

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

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

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

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

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