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

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

k = A("k")
d = B("d")
g = A("g")

k.p = g
d.s = k
g.p = k
assert k.p.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.s: A = None
        self.txt = txt

k = A("k")
d = B("d")
g = A("g")

k.p = g
d.s = k
g.p = k
assert k.p.p.p.txt == "g"