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

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

a = A("a")
b = B("b")
c = A("c")
i = A("i")
g = B("g")
h = B("h")

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

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

a = A("a")
b = B("b")
c = A("c")
i = A("i")
g = B("g")
h = B("h")

a.t = b
b.w = g
b.s = h
c.t = b
i.t = h
g.w = h
g.s = h
h.w = b
h.s = g
assert g.s.w.w.s.w.txt == "b"