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

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

i = A("i")
k = B("k")
h = A("h")
c = B("c")

i.q = c
i.p = h
k.x = i
h.q = c
h.p = i
c.x = h
assert i.q.x.p.q.txt == "
class A:
    def __init__(self, txt: str):
        self.q: B = None
        self.p: A = None
        self.txt = txt

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

i = A("i")
k = B("k")
h = A("h")
c = B("c")

i.q = c
i.p = h
k.x = i
h.q = c
h.p = i
c.x = h
assert i.q.x.p.q.txt == "c"