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

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

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

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

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

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

k.z = f
k.o = f
b.y = k
f.z = k
f.o = k
assert f.o.z.z.txt == "k"