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

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

h = A("h")
j = B("j")
k = B("k")
a = A("a")

h.s = j
h.q = k
j.y = h
k.y = h
a.s = k
a.q = j
assert j.y.s.y.q.txt == "
class A:
    def __init__(self, txt: str):
        self.s: B = None
        self.q: B = None
        self.txt = txt

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

h = A("h")
j = B("j")
k = B("k")
a = A("a")

h.s = j
h.q = k
j.y = h
k.y = h
a.s = k
a.q = j
assert j.y.s.y.q.txt == "k"