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

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

m = A("m")
i = B("i")
g = A("g")
l = A("l")
d = B("d")
a = B("a")

m.v = d
i.p = g
i.t = d
g.v = d
l.v = a
d.p = m
d.t = i
a.p = m
a.t = d
assert g.v.t.t.txt == "
class A:
    def __init__(self, txt: str):
        self.v: B = None
        self.txt = txt

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

m = A("m")
i = B("i")
g = A("g")
l = A("l")
d = B("d")
a = B("a")

m.v = d
i.p = g
i.t = d
g.v = d
l.v = a
d.p = m
d.t = i
a.p = m
a.t = d
assert g.v.t.t.txt == "d"