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

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

g = A("g")
j = B("j")
f = A("f")
k = A("k")
a = B("a")
h = A("h")
b = A("b")
i = B("i")
m = B("m")

g.w = k
j.r = a
f.w = h
k.w = g
a.r = j
h.w = k
b.w = f
i.r = m
m.r = i
assert i.r.r.r.r.r.txt == "
class A:
    def __init__(self, txt: str):
        self.w: A = None
        self.txt = txt

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

g = A("g")
j = B("j")
f = A("f")
k = A("k")
a = B("a")
h = A("h")
b = A("b")
i = B("i")
m = B("m")

g.w = k
j.r = a
f.w = h
k.w = g
a.r = j
h.w = k
b.w = f
i.r = m
m.r = i
assert i.r.r.r.r.r.txt == "m"