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

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

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

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

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

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

k.s = j
k.p = j
e.y = k
f.y = j
n.y = k
h.y = j
j.s = k
j.p = k
assert e.y.s.p.p.txt == "j"