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

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

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

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

e = A("e")
h = B("h")
g = C("g")
a = D("a")
c = A("c")

e.q = a
h.r = c
g.q = c
a.t = g
a.p = g
a.q = h
c.q = a
assert g.q.q.q.r.q.txt == "
class A:
    def __init__(self, txt: str):
        self.q: D = None
        self.txt = txt

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

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

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

e = A("e")
h = B("h")
g = C("g")
a = D("a")
c = A("c")

e.q = a
h.r = c
g.q = c
a.t = g
a.p = g
a.q = h
c.q = a
assert g.q.q.q.r.q.txt == "a"