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

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

k = A("k")
m = B("m")
d = B("d")
g = A("g")

k.v = m
k.y = d
m.p = g
m.q = d
d.p = g
d.q = m
g.v = d
g.y = m
assert d.q.q.p.y.txt == "
class A:
    def __init__(self, txt: str):
        self.v: B = None
        self.y: B = None
        self.txt = txt

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

k = A("k")
m = B("m")
d = B("d")
g = A("g")

k.v = m
k.y = d
m.p = g
m.q = d
d.p = g
d.q = m
g.v = d
g.y = m
assert d.q.q.p.y.txt == "m"