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

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

d = A("d")
l = B("l")
e = A("e")
m = A("m")
a = B("a")
b = A("b")
i = B("i")
c = A("c")

d.p = l
d.v = m
l.x = i
l.q = d
e.p = i
e.v = c
m.p = a
m.v = c
a.x = l
a.q = m
b.p = l
b.v = d
i.x = l
i.q = b
c.p = a
c.v = m
assert a.q.v.v.v.p.q.p.txt == "
class A:
    def __init__(self, txt: str):
        self.p: B = None
        self.v: A = None
        self.txt = txt

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

d = A("d")
l = B("l")
e = A("e")
m = A("m")
a = B("a")
b = A("b")
i = B("i")
c = A("c")

d.p = l
d.v = m
l.x = i
l.q = d
e.p = i
e.v = c
m.p = a
m.v = c
a.x = l
a.q = m
b.p = l
b.v = d
i.x = l
i.q = b
c.p = a
c.v = m
assert a.q.v.v.v.p.q.p.txt == "a"