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

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

k = A("k")
i = B("i")
g = B("g")
h = A("h")

k.s = h
k.p = i
i.s = h
g.s = k
h.s = k
h.p = i
assert i.s.p.s.txt == "
class A:
    def __init__(self, txt: str):
        self.s: A = None
        self.p: B = None
        self.txt = txt

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

k = A("k")
i = B("i")
g = B("g")
h = A("h")

k.s = h
k.p = i
i.s = h
g.s = k
h.s = k
h.p = i
assert i.s.p.s.txt == "h"