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

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

e = A("e")
b = B("b")
h = B("h")
l = A("l")
c = B("c")
f = B("f")
g = B("g")

e.u = h
b.w = c
h.w = g
l.u = f
c.w = g
f.w = b
g.w = c
assert g.w.w.w.txt == "
class A:
    def __init__(self, txt: str):
        self.u: B = None
        self.txt = txt

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

e = A("e")
b = B("b")
h = B("h")
l = A("l")
c = B("c")
f = B("f")
g = B("g")

e.u = h
b.w = c
h.w = g
l.u = f
c.w = g
f.w = b
g.w = c
assert g.w.w.w.txt == "c"