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

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

g = A("g")
k = B("k")
d = B("d")
n = B("n")
i = B("i")
h = B("h")

g.p = k
k.r = d
k.u = g
d.r = i
d.u = g
n.r = k
n.u = g
i.r = k
i.u = g
h.r = n
h.u = g
assert g.p.r.r.u.p.txt == "
class A:
    def __init__(self, txt: str):
        self.p: B = None
        self.txt = txt

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

g = A("g")
k = B("k")
d = B("d")
n = B("n")
i = B("i")
h = B("h")

g.p = k
k.r = d
k.u = g
d.r = i
d.u = g
n.r = k
n.u = g
i.r = k
i.u = g
h.r = n
h.u = g
assert g.p.r.r.u.p.txt == "k"