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

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

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

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

a = A("a")
i = B("i")
k = C("k")
e = D("e")
g = A("g")

a.t = i
i.r = g
i.t = k
i.p = k
i.o = e
k.t = e
e.q = g
g.t = i
assert i.r.t.r.txt == "
class A:
    def __init__(self, txt: str):
        self.t: B = None
        self.txt = txt

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

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

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

a = A("a")
i = B("i")
k = C("k")
e = D("e")
g = A("g")

a.t = i
i.r = g
i.t = k
i.p = k
i.o = e
k.t = e
e.q = g
g.t = i
assert i.r.t.r.txt == "g"