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

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

g = A("g")
i = B("i")
c = B("c")
m = A("m")
f = A("f")
b = A("b")
n = B("n")
l = A("l")

g.w = m
i.u = l
c.u = g
m.w = f
f.w = b
b.w = m
n.u = g
l.w = g
assert g.w.w.w.w.txt == "
class A:
    def __init__(self, txt: str):
        self.w: A = None
        self.txt = txt

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

g = A("g")
i = B("i")
c = B("c")
m = A("m")
f = A("f")
b = A("b")
n = B("n")
l = A("l")

g.w = m
i.u = l
c.u = g
m.w = f
f.w = b
b.w = m
n.u = g
l.w = g
assert g.w.w.w.w.txt == "m"