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

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

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

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

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

class F:
    def __init__(self, txt: str):
        self.w: B = None
        self.txt = txt

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

g.z = n
g.r = n
i.x = k
i.r = h
a.q = h
l.p = i
l.w = i
h.q = a
k.w = i
d.w = i
n.z = g
n.r = g
assert d.w.r.q.q.txt == "
class A:
    def __init__(self, txt: str):
        self.z: A = None
        self.r: A = None
        self.txt = txt

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

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

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

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

class F:
    def __init__(self, txt: str):
        self.w: B = None
        self.txt = txt

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

g.z = n
g.r = n
i.x = k
i.r = h
a.q = h
l.p = i
l.w = i
h.q = a
k.w = i
d.w = i
n.z = g
n.r = g
assert d.w.r.q.q.txt == "h"