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

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

i = A("i")
m = B("m")
k = B("k")
e = B("e")
l = B("l")
f = B("f")
n = A("n")
c = A("c")
d = B("d")

i.r = n
i.q = d
m.t = c
k.t = i
e.t = c
l.t = n
f.t = c
n.r = i
n.q = m
c.r = n
c.q = m
d.t = n
assert f.t.q.t.r.txt == "
class A:
    def __init__(self, txt: str):
        self.r: A = None
        self.q: B = None
        self.txt = txt

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

i = A("i")
m = B("m")
k = B("k")
e = B("e")
l = B("l")
f = B("f")
n = A("n")
c = A("c")
d = B("d")

i.r = n
i.q = d
m.t = c
k.t = i
e.t = c
l.t = n
f.t = c
n.r = i
n.q = m
c.r = n
c.q = m
d.t = n
assert f.t.q.t.r.txt == "n"