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

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

class C:
    def __init__(self, txt: str):
        self.r: D = None
        self.txt = txt

class D:
    def __init__(self, txt: str):
        self.q: C = None
        self.txt = txt

class E:
    def __init__(self, txt: str):
        self.v: B = None
        self.s: E = None
        self.txt = txt

class F:
    def __init__(self, txt: str):
        self.s: A = None
        self.p: A = None
        self.x: D = None
        self.txt = txt

n = A("n")
c = B("c")
h = C("h")
m = D("m")
j = E("j")
i = F("i")
b = E("b")

n.s = m
c.q = n
c.x = i
h.r = m
m.q = h
j.v = c
j.s = b
i.s = n
i.p = n
i.x = m
b.v = c
b.s = j
assert b.s.v.q.s.txt == "
class A:
    def __init__(self, txt: str):
        self.s: D = None
        self.txt = txt

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

class C:
    def __init__(self, txt: str):
        self.r: D = None
        self.txt = txt

class D:
    def __init__(self, txt: str):
        self.q: C = None
        self.txt = txt

class E:
    def __init__(self, txt: str):
        self.v: B = None
        self.s: E = None
        self.txt = txt

class F:
    def __init__(self, txt: str):
        self.s: A = None
        self.p: A = None
        self.x: D = None
        self.txt = txt

n = A("n")
c = B("c")
h = C("h")
m = D("m")
j = E("j")
i = F("i")
b = E("b")

n.s = m
c.q = n
c.x = i
h.r = m
m.q = h
j.v = c
j.s = b
i.s = n
i.p = n
i.x = m
b.v = c
b.s = j
assert b.s.v.q.s.txt == "m"