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

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

l = A("l")
e = B("e")
d = B("d")
c = A("c")
g = A("g")

l.p = e
l.v = e
e.q = c
e.o = l
d.q = g
d.o = l
c.p = d
c.v = e
g.p = e
g.v = e
assert d.o.v.q.p.o.txt == "
class A:
    def __init__(self, txt: str):
        self.p: B = None
        self.v: B = None
        self.txt = txt

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

l = A("l")
e = B("e")
d = B("d")
c = A("c")
g = A("g")

l.p = e
l.v = e
e.q = c
e.o = l
d.q = g
d.o = l
c.p = d
c.v = e
g.p = e
g.v = e
assert d.o.v.q.p.o.txt == "l"