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

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

k = A("k")
j = B("j")
f = A("f")

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

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

k = A("k")
j = B("j")
f = A("f")

k.p = j
k.q = j
j.v = k
f.p = j
f.q = j
assert k.p.v.q.txt == "j"