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

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

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

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

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

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

k.p = e
k.y = f
a.r = e
f.p = e
f.y = k
e.r = a
i.p = a
i.y = k
assert i.p.r.r.txt == "a"