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

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

a = A("a")
f = B("f")
k = B("k")
h = A("h")
n = A("n")

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

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

a = A("a")
f = B("f")
k = B("k")
h = A("h")
n = A("n")

a.p = k
a.s = f
f.y = h
f.t = k
k.y = a
k.t = f
h.p = f
h.s = k
n.p = f
n.s = k
assert h.p.t.y.txt == "a"