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

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

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

class D:
    def __init__(self, txt: str):
        self.y: A = None
        self.p: F = None
        self.x: F = None
        self.w: C = None
        self.r: G = None
        self.q: E = None
        self.txt = txt

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

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

class G:
    def __init__(self, txt: str):
        self.t: D = None
        self.v: E = None
        self.o: A = None
        self.p: C = None
        self.txt = txt

n = A("n")
h = B("h")
g = C("g")
a = D("a")
i = E("i")
f = F("f")
d = G("d")

n.x = g
h.q = a
h.p = a
h.y = n
g.q = n
g.r = a
a.y = n
a.p = f
a.x = f
a.w = g
a.r = d
a.q = i
i.t = g
i.w = a
f.v = i
f.s = n
f.o = n
d.t = a
d.v = i
d.o = n
d.p = g
assert d.t.r.p.txt == "
class A:
    def __init__(self, txt: str):
        self.x: C = None
        self.txt = txt

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

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

class D:
    def __init__(self, txt: str):
        self.y: A = None
        self.p: F = None
        self.x: F = None
        self.w: C = None
        self.r: G = None
        self.q: E = None
        self.txt = txt

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

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

class G:
    def __init__(self, txt: str):
        self.t: D = None
        self.v: E = None
        self.o: A = None
        self.p: C = None
        self.txt = txt

n = A("n")
h = B("h")
g = C("g")
a = D("a")
i = E("i")
f = F("f")
d = G("d")

n.x = g
h.q = a
h.p = a
h.y = n
g.q = n
g.r = a
a.y = n
a.p = f
a.x = f
a.w = g
a.r = d
a.q = i
i.t = g
i.w = a
f.v = i
f.s = n
f.o = n
d.t = a
d.v = i
d.o = n
d.p = g
assert d.t.r.p.txt == "g"