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

class B:
    def __init__(self, txt: str):
        self.u: C = None
        self.y: C = None
        self.x: C = None
        self.o: B = None
        self.txt = txt

class C:
    def __init__(self, txt: str):
        self.x: B = None
        self.y: D = None
        self.r: B = None
        self.txt = txt

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

j = A("j")
k = B("k")
c = C("c")
a = D("a")
b = D("b")
d = B("d")
g = C("g")

j.x = c
k.u = c
k.x = c
k.y = g
k.o = d
c.x = k
c.r = k
c.y = a
a.r = b
a.s = b
a.y = c
a.p = j
b.r = a
b.s = a
b.y = g
b.p = j
d.u = g
d.y = g
d.x = c
d.o = k
g.x = d
g.y = b
g.r = k
assert a.y.y.p.x.y.p.txt == "
class A:
    def __init__(self, txt: str):
        self.x: C = None
        self.txt = txt

class B:
    def __init__(self, txt: str):
        self.u: C = None
        self.y: C = None
        self.x: C = None
        self.o: B = None
        self.txt = txt

class C:
    def __init__(self, txt: str):
        self.x: B = None
        self.y: D = None
        self.r: B = None
        self.txt = txt

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

j = A("j")
k = B("k")
c = C("c")
a = D("a")
b = D("b")
d = B("d")
g = C("g")

j.x = c
k.u = c
k.x = c
k.y = g
k.o = d
c.x = k
c.r = k
c.y = a
a.r = b
a.s = b
a.y = c
a.p = j
b.r = a
b.s = a
b.y = g
b.p = j
d.u = g
d.y = g
d.x = c
d.o = k
g.x = d
g.y = b
g.r = k
assert a.y.y.p.x.y.p.txt == "j"