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

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

g = A("g")
k = B("k")
f = B("f")
l = B("l")
a = A("a")

g.r = a
g.z = a
k.r = l
f.r = l
l.r = f
a.r = g
a.z = g
assert k.r.r.r.r.r.txt == "
class A:
    def __init__(self, txt: str):
        self.r: A = None
        self.z: A = None
        self.txt = txt

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

g = A("g")
k = B("k")
f = B("f")
l = B("l")
a = A("a")

g.r = a
g.z = a
k.r = l
f.r = l
l.r = f
a.r = g
a.z = g
assert k.r.r.r.r.r.txt == "l"