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

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

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

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

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

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

i.u = g
c.s = h
c.w = f
g.s = i
g.w = c
a.s = i
a.w = c
f.s = i
f.w = g
h.u = g
assert g.w.w.w.s.txt == "i"