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

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

g = A("g")
n = B("n")
a = A("a")
h = B("h")

g.u = a
g.p = a
n.y = h
a.u = g
a.p = g
h.y = n
assert n.y.y.y.y.txt == "
class A:
    def __init__(self, txt: str):
        self.u: A = None
        self.p: A = None
        self.txt = txt

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

g = A("g")
n = B("n")
a = A("a")
h = B("h")

g.u = a
g.p = a
n.y = h
a.u = g
a.p = g
h.y = n
assert n.y.y.y.y.txt == "n"