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

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

class C:
    def __init__(self, txt: str):
        self.s: E = None
        self.q: A = None
        self.txt = txt

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

class E:
    def __init__(self, txt: str):
        self.s: F = None
        self.w: C = None
        self.txt = txt

class F:
    def __init__(self, txt: str):
        self.x: C = None
        self.u: C = None
        self.txt = txt

j = A("j")
g = B("g")
m = C("m")
h = D("h")
f = E("f")
k = F("k")

j.x = h
j.r = h
j.q = h
g.x = m
g.s = h
g.p = h
g.z = k
m.s = f
m.q = j
h.p = m
h.s = k
h.y = j
f.s = k
f.w = m
k.x = m
k.u = m
assert j.r.p.s.txt == "
class A:
    def __init__(self, txt: str):
        self.x: D = None
        self.r: D = None
        self.q: D = None
        self.txt = txt

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

class C:
    def __init__(self, txt: str):
        self.s: E = None
        self.q: A = None
        self.txt = txt

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

class E:
    def __init__(self, txt: str):
        self.s: F = None
        self.w: C = None
        self.txt = txt

class F:
    def __init__(self, txt: str):
        self.x: C = None
        self.u: C = None
        self.txt = txt

j = A("j")
g = B("g")
m = C("m")
h = D("h")
f = E("f")
k = F("k")

j.x = h
j.r = h
j.q = h
g.x = m
g.s = h
g.p = h
g.z = k
m.s = f
m.q = j
h.p = m
h.s = k
h.y = j
f.s = k
f.w = m
k.x = m
k.u = m
assert j.r.p.s.txt == "f"