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

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

h = A("h")
d = B("d")
a = B("a")
c = A("c")
j = B("j")
n = A("n")

h.u = c
d.p = j
d.v = n
a.p = d
a.v = h
c.u = h
j.p = d
j.v = c
n.u = c
assert a.p.v.u.u.u.u.txt == "
class A:
    def __init__(self, txt: str):
        self.u: A = None
        self.txt = txt

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

h = A("h")
d = B("d")
a = B("a")
c = A("c")
j = B("j")
n = A("n")

h.u = c
d.p = j
d.v = n
a.p = d
a.v = h
c.u = h
j.p = d
j.v = c
n.u = c
assert a.p.v.u.u.u.u.txt == "h"