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

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

k = A("k")
f = B("f")
i = B("i")
a = A("a")

k.p = i
k.y = f
f.z = k
i.z = a
a.p = i
a.y = i
assert i.z.y.z.txt == "
class A:
    def __init__(self, txt: str):
        self.p: B = None
        self.y: B = None
        self.txt = txt

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

k = A("k")
f = B("f")
i = B("i")
a = A("a")

k.p = i
k.y = f
f.z = k
i.z = a
a.p = i
a.y = i
assert i.z.y.z.txt == "a"