class A:
    def __init__(self, txt: str):
        self.u: 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")
d = B("d")
i = A("i")
g = B("g")
e = B("e")

k.u = i
k.p = g
d.s = k
i.u = k
i.p = d
g.s = i
e.s = k
assert k.p.s.u.p.txt == "
class A:
    def __init__(self, txt: str):
        self.u: 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")
d = B("d")
i = A("i")
g = B("g")
e = B("e")

k.u = i
k.p = g
d.s = k
i.u = k
i.p = d
g.s = i
e.s = k
assert k.p.s.u.p.txt == "g"