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

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

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

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

j = A("j")
d = B("d")
e = C("e")
n = D("n")
g = C("g")
c = B("c")

j.q = e
d.p = g
e.p = c
e.o = n
e.r = j
n.z = j
g.p = d
g.o = n
g.r = j
c.p = g
assert j.q.p.p.txt == "
class A:
    def __init__(self, txt: str):
        self.q: C = None
        self.txt = txt

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

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

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

j = A("j")
d = B("d")
e = C("e")
n = D("n")
g = C("g")
c = B("c")

j.q = e
d.p = g
e.p = c
e.o = n
e.r = j
n.z = j
g.p = d
g.o = n
g.r = j
c.p = g
assert j.q.p.p.txt == "g"