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

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

f = A("f")
i = B("i")
a = B("a")
l = B("l")
k = B("k")
j = A("j")
h = A("h")

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

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

f = A("f")
i = B("i")
a = B("a")
l = B("l")
k = B("k")
j = A("j")
h = A("h")

f.q = k
f.t = j
i.u = l
i.r = j
a.u = i
a.r = j
l.u = i
l.r = h
k.u = l
k.r = j
j.q = k
j.t = f
h.q = a
h.t = j
assert j.t.t.q.r.txt == "j"