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

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

k = A("k")
a = B("a")
f = B("f")
d = B("d")

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

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

k = A("k")
a = B("a")
f = B("f")
d = B("d")

k.v = f
k.p = f
a.q = k
a.p = d
f.q = k
f.p = a
d.q = k
d.p = f
assert k.v.p.q.txt == "k"