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

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

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

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

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

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

k.o = l
k.p = i
g.p = k
i.p = k
l.o = h
l.p = g
h.o = l
h.p = i
assert k.p.p.p.p.txt == "k"