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

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

c = A("c")
h = B("h")
b = A("b")

c.q = h
c.r = b
h.y = c
b.q = h
b.r = c
assert c.q.y.q.txt == "
class A:
    def __init__(self, txt: str):
        self.q: B = None
        self.r: A = None
        self.txt = txt

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

c = A("c")
h = B("h")
b = A("b")

c.q = h
c.r = b
h.y = c
b.q = h
b.r = c
assert c.q.y.q.txt == "h"