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

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

h = A("h")
m = B("m")
n = A("n")
c = A("c")
b = A("b")
d = B("d")
a = A("a")
j = A("j")
k = B("k")

h.x = j
m.q = k
m.r = d
n.x = a
c.x = j
b.x = a
d.q = m
d.r = k
a.x = h
j.x = n
k.q = m
k.r = m
assert n.x.x.x.x.x.x.txt == "
class A:
    def __init__(self, txt: str):
        self.x: A = None
        self.txt = txt

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

h = A("h")
m = B("m")
n = A("n")
c = A("c")
b = A("b")
d = B("d")
a = A("a")
j = A("j")
k = B("k")

h.x = j
m.q = k
m.r = d
n.x = a
c.x = j
b.x = a
d.q = m
d.r = k
a.x = h
j.x = n
k.q = m
k.r = m
assert n.x.x.x.x.x.x.txt == "h"