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

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

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

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

class E:
    def __init__(self, txt: str):
        self.q: D = None
        self.s: F = None
        self.o: B = None
        self.txt = txt

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

a = A("a")
k = B("k")
h = C("h")
d = D("d")
j = E("j")
m = F("m")

a.q = m
k.v = a
k.q = m
h.x = d
d.p = m
j.q = d
j.s = m
j.o = k
m.q = j
m.v = a
assert d.p.v.q.v.q.txt == "
class A:
    def __init__(self, txt: str):
        self.q: F = None
        self.txt = txt

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

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

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

class E:
    def __init__(self, txt: str):
        self.q: D = None
        self.s: F = None
        self.o: B = None
        self.txt = txt

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

a = A("a")
k = B("k")
h = C("h")
d = D("d")
j = E("j")
m = F("m")

a.q = m
k.v = a
k.q = m
h.x = d
d.p = m
j.q = d
j.s = m
j.o = k
m.q = j
m.v = a
assert d.p.v.q.v.q.txt == "m"