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

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

a = A("a")
f = B("f")
d = A("d")
b = B("b")
c = B("c")
h = B("h")
m = A("m")
e = A("e")
j = B("j")
g = B("g")

a.w = e
f.w = h
d.w = m
b.w = f
c.w = h
h.w = b
m.w = a
e.w = m
j.w = f
g.w = j
assert c.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.w: B = None
        self.txt = txt

a = A("a")
f = B("f")
d = A("d")
b = B("b")
c = B("c")
h = B("h")
m = A("m")
e = A("e")
j = B("j")
g = B("g")

a.w = e
f.w = h
d.w = m
b.w = f
c.w = h
h.w = b
m.w = a
e.w = m
j.w = f
g.w = j
assert c.w.w.w.txt == "f"