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

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

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

n.y = e
n.z = c
b.y = g
b.o = n
d.q = e
c.o = j
c.p = j
c.q = d
i.q = n
j.o = c
j.p = c
j.q = d
e.y = n
e.z = j
l.y = b
l.o = e
g.y = l
g.o = n
assert b.o.y.y.txt == "
class A:
    def __init__(self, txt: str):
        self.y: A = None
        self.z: D = None
        self.txt = txt

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

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

n.y = e
n.z = c
b.y = g
b.o = n
d.q = e
c.o = j
c.p = j
c.q = d
i.q = n
j.o = c
j.p = c
j.q = d
e.y = n
e.z = j
l.y = b
l.o = e
g.y = l
g.o = n
assert b.o.y.y.txt == "n"