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

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

h = A("h")
e = B("e")
g = B("g")
b = A("b")
a = B("a")

h.u = g
h.p = b
e.z = g
e.s = g
g.z = e
g.s = a
b.u = a
b.p = h
a.z = g
a.s = e
assert e.z.z.s.txt == "
class A:
    def __init__(self, txt: str):
        self.u: B = None
        self.p: A = None
        self.txt = txt

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

h = A("h")
e = B("e")
g = B("g")
b = A("b")
a = B("a")

h.u = g
h.p = b
e.z = g
e.s = g
g.z = e
g.s = a
b.u = a
b.p = h
a.z = g
a.s = e
assert e.z.z.s.txt == "g"