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

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

m = A("m")
a = B("a")
i = B("i")
e = B("e")
f = A("f")
j = B("j")
n = B("n")
g = B("g")
k = A("k")

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

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

m = A("m")
a = B("a")
i = B("i")
e = B("e")
f = A("f")
j = B("j")
n = B("n")
g = B("g")
k = A("k")

m.x = k
a.r = j
i.r = g
e.r = i
f.x = m
j.r = n
n.r = i
g.r = n
k.x = m
assert j.r.r.r.txt == "g"