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

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

h = A("h")
g = B("g")
d = B("d")
j = B("j")
i = B("i")
n = A("n")
c = B("c")
m = B("m")

h.q = i
g.q = n
g.t = h
d.q = n
d.t = n
j.q = h
j.t = h
i.q = n
i.t = n
n.q = i
c.q = n
c.t = h
m.q = n
m.t = h
assert i.q.q.t.q.q.q.txt == "
class A:
    def __init__(self, txt: str):
        self.q: B = None
        self.txt = txt

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

h = A("h")
g = B("g")
d = B("d")
j = B("j")
i = B("i")
n = A("n")
c = B("c")
m = B("m")

h.q = i
g.q = n
g.t = h
d.q = n
d.t = n
j.q = h
j.t = h
i.q = n
i.t = n
n.q = i
c.q = n
c.t = h
m.q = n
m.t = h
assert i.q.q.t.q.q.q.txt == "i"