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

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

h = A("h")
a = B("a")
l = B("l")
g = A("g")
j = B("j")
n = B("n")
d = A("d")
i = A("i")
c = A("c")
k = B("k")

h.v = i
h.q = n
a.p = c
l.p = h
g.v = c
g.q = a
j.p = g
n.p = h
d.v = c
d.q = n
i.v = c
i.q = a
c.v = d
c.q = a
k.p = i
assert j.p.v.v.txt == "
class A:
    def __init__(self, txt: str):
        self.v: A = None
        self.q: B = None
        self.txt = txt

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

h = A("h")
a = B("a")
l = B("l")
g = A("g")
j = B("j")
n = B("n")
d = A("d")
i = A("i")
c = A("c")
k = B("k")

h.v = i
h.q = n
a.p = c
l.p = h
g.v = c
g.q = a
j.p = g
n.p = h
d.v = c
d.q = n
i.v = c
i.q = a
c.v = d
c.q = a
k.p = i
assert j.p.v.v.txt == "d"