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

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

b = A("b")
d = B("d")
k = B("k")
h = A("h")

b.v = d
b.q = d
d.s = h
k.s = h
h.v = d
h.q = d
assert k.s.v.s.v.txt == "
class A:
    def __init__(self, txt: str):
        self.v: B = None
        self.q: B = None
        self.txt = txt

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

b = A("b")
d = B("d")
k = B("k")
h = A("h")

b.v = d
b.q = d
d.s = h
k.s = h
h.v = d
h.q = d
assert k.s.v.s.v.txt == "d"