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

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

j = A("j")
g = B("g")
c = B("c")
b = A("b")

j.y = b
j.z = b
g.q = c
c.q = g
b.y = j
b.z = j
assert b.y.z.y.txt == "
class A:
    def __init__(self, txt: str):
        self.y: A = None
        self.z: A = None
        self.txt = txt

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

j = A("j")
g = B("g")
c = B("c")
b = A("b")

j.y = b
j.z = b
g.q = c
c.q = g
b.y = j
b.z = j
assert b.y.z.y.txt == "j"