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

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

class C:
    def __init__(self, txt: str):
        self.t: B = None
        self.txt = txt

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

i = A("i")
b = B("b")
d = C("d")
n = D("n")
g = D("g")
e = B("e")
a = D("a")

i.o = d
b.q = i
b.y = n
d.t = e
n.t = d
n.o = i
g.t = d
g.o = i
e.q = i
e.y = a
a.t = d
a.o = i
assert g.o.o.t.y.txt == "
class A:
    def __init__(self, txt: str):
        self.o: C = None
        self.txt = txt

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

class C:
    def __init__(self, txt: str):
        self.t: B = None
        self.txt = txt

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

i = A("i")
b = B("b")
d = C("d")
n = D("n")
g = D("g")
e = B("e")
a = D("a")

i.o = d
b.q = i
b.y = n
d.t = e
n.t = d
n.o = i
g.t = d
g.o = i
e.q = i
e.y = a
a.t = d
a.o = i
assert g.o.o.t.y.txt == "a"