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.y: A = None
        self.txt = txt

f = A("f")
h = B("h")
b = A("b")
a = A("a")
n = A("n")
k = B("k")
l = A("l")
g = A("g")

f.w = a
h.u = b
h.y = a
b.w = l
a.w = g
n.w = l
k.u = f
k.y = f
l.w = b
g.w = a
assert f.w.w.w.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.y: A = None
        self.txt = txt

f = A("f")
h = B("h")
b = A("b")
a = A("a")
n = A("n")
k = B("k")
l = A("l")
g = A("g")

f.w = a
h.u = b
h.y = a
b.w = l
a.w = g
n.w = l
k.u = f
k.y = f
l.w = b
g.w = a
assert f.w.w.w.w.w.w.w.txt == "a"