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

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

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

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

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

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

i.q = m
l.t = f
j.q = m
m.q = i
f.t = l
h.t = f
assert j.q.q.q.q.txt == "i"