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

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

k = A("k")
j = B("j")
h = A("h")
e = A("e")

k.p = e
j.r = k
h.p = k
e.p = k
assert j.r.p.p.txt == "
class A:
    def __init__(self, txt: str):
        self.p: A = None
        self.txt = txt

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

k = A("k")
j = B("j")
h = A("h")
e = A("e")

k.p = e
j.r = k
h.p = k
e.p = k
assert j.r.p.p.txt == "k"