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

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

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

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

c = A("c")
g = B("g")
i = C("i")
d = D("d")
k = A("k")
n = A("n")

c.p = k
c.o = n
g.q = n
g.u = d
g.x = d
i.q = d
i.s = d
d.q = n
d.u = c
k.p = n
k.o = n
n.p = c
n.o = k
assert g.x.q.p.txt == "
class A:
    def __init__(self, txt: str):
        self.p: A = None
        self.o: A = None
        self.txt = txt

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

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

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

c = A("c")
g = B("g")
i = C("i")
d = D("d")
k = A("k")
n = A("n")

c.p = k
c.o = n
g.q = n
g.u = d
g.x = d
i.q = d
i.s = d
d.q = n
d.u = c
k.p = n
k.o = n
n.p = c
n.o = k
assert g.x.q.p.txt == "c"