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

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

h = A("h")
j = B("j")
i = A("i")
f = B("f")

h.y = f
h.t = i
j.q = f
j.u = h
i.y = f
i.t = h
f.q = j
f.u = i
assert f.q.u.y.u.txt == "
class A:
    def __init__(self, txt: str):
        self.y: B = None
        self.t: A = None
        self.txt = txt

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

h = A("h")
j = B("j")
i = A("i")
f = B("f")

h.y = f
h.t = i
j.q = f
j.u = h
i.y = f
i.t = h
f.q = j
f.u = i
assert f.q.u.y.u.txt == "i"