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

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

n = A("n")
b = B("b")
k = B("k")
f = A("f")

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

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

n = A("n")
b = B("b")
k = B("k")
f = A("f")

n.z = f
b.r = f
k.r = f
f.z = n
assert b.r.z.z.txt == "f"