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.x: B = None
        self.txt = txt

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

m.q = g
g.q = f
g.x = i
i.q = d
i.x = g
d.q = h
h.q = m
h.x = i
n.q = d
n.x = h
c.q = i
f.q = g
assert i.q.q.x.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.x: B = None
        self.txt = txt

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

m.q = g
g.q = f
g.x = i
i.q = d
i.x = g
d.q = h
h.q = m
h.x = i
n.q = d
n.x = h
c.q = i
f.q = g
assert i.q.q.x.q.txt == "d"