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

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

l = A("l")
e = B("e")
d = B("d")
b = B("b")
i = A("i")
g = A("g")

l.v = g
l.p = g
e.s = i
d.s = i
b.s = i
i.v = g
i.p = l
g.v = i
g.p = l
assert e.s.v.v.p.v.txt == "
class A:
    def __init__(self, txt: str):
        self.v: A = None
        self.p: A = None
        self.txt = txt

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

l = A("l")
e = B("e")
d = B("d")
b = B("b")
i = A("i")
g = A("g")

l.v = g
l.p = g
e.s = i
d.s = i
b.s = i
i.v = g
i.p = l
g.v = i
g.p = l
assert e.s.v.v.p.v.txt == "g"