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

class B:
    def __init__(self, txt: str):
        self.q: E = 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.y: B = None
        self.txt = txt

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

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

class G:
    def __init__(self, txt: str):
        self.z: C = None
        self.txt = txt

d = A("d")
m = B("m")
k = C("k")
f = D("f")
j = E("j")
b = F("b")
h = G("h")
l = F("l")

d.q = h
d.r = f
m.q = j
k.r = f
f.y = m
j.w = m
b.o = d
b.q = f
h.z = k
l.o = d
l.q = f
assert j.w.q.w.q.w.q.txt == "
class A:
    def __init__(self, txt: str):
        self.q: G = None
        self.r: D = None
        self.txt = txt

class B:
    def __init__(self, txt: str):
        self.q: E = 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.y: B = None
        self.txt = txt

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

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

class G:
    def __init__(self, txt: str):
        self.z: C = None
        self.txt = txt

d = A("d")
m = B("m")
k = C("k")
f = D("f")
j = E("j")
b = F("b")
h = G("h")
l = F("l")

d.q = h
d.r = f
m.q = j
k.r = f
f.y = m
j.w = m
b.o = d
b.q = f
h.z = k
l.o = d
l.q = f
assert j.w.q.w.q.w.q.txt == "j"