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

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

a = A("a")
f = B("f")
m = B("m")
n = A("n")
d = B("d")
j = A("j")
b = A("b")

a.y = n
f.y = a
f.w = d
m.y = n
m.w = f
n.y = j
d.y = a
d.w = f
j.y = a
b.y = n
assert d.w.y.y.y.y.y.txt == "
class A:
    def __init__(self, txt: str):
        self.y: A = None
        self.txt = txt

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

a = A("a")
f = B("f")
m = B("m")
n = A("n")
d = B("d")
j = A("j")
b = A("b")

a.y = n
f.y = a
f.w = d
m.y = n
m.w = f
n.y = j
d.y = a
d.w = f
j.y = a
b.y = n
assert d.w.y.y.y.y.y.txt == "n"