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

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

h = A("h")
a = B("a")
c = B("c")
i = A("i")
g = A("g")
e = A("e")
n = B("n")
k = A("k")

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

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

h = A("h")
a = B("a")
c = B("c")
i = A("i")
g = A("g")
e = A("e")
n = B("n")
k = A("k")

h.v = a
h.p = n
a.r = n
a.q = i
c.r = a
c.q = k
i.v = a
i.p = a
g.v = c
g.p = n
e.v = a
e.p = c
n.r = a
n.q = k
k.v = a
k.p = a
assert e.p.q.v.txt == "a"