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

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

g = A("g")
b = B("b")
n = A("n")
c = A("c")
a = B("a")
d = A("d")
j = A("j")

g.x = c
g.y = b
b.u = d
b.r = c
n.x = c
n.y = a
c.x = g
c.y = a
a.u = j
a.r = j
d.x = g
d.y = a
j.x = c
j.y = b
assert d.x.x.y.r.x.y.txt == "
class A:
    def __init__(self, txt: str):
        self.x: A = None
        self.y: B = None
        self.txt = txt

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

g = A("g")
b = B("b")
n = A("n")
c = A("c")
a = B("a")
d = A("d")
j = A("j")

g.x = c
g.y = b
b.u = d
b.r = c
n.x = c
n.y = a
c.x = g
c.y = a
a.u = j
a.r = j
d.x = g
d.y = a
j.x = c
j.y = b
assert d.x.x.y.r.x.y.txt == "a"