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

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

e = A("e")
k = B("k")
d = B("d")
n = A("n")
h = B("h")
c = A("c")
a = B("a")
b = B("b")
f = A("f")

e.r = n
e.x = f
k.y = b
k.x = c
d.y = k
d.x = n
n.r = c
n.x = f
h.y = d
h.x = e
c.r = n
c.x = f
a.y = b
a.x = f
b.y = h
b.x = n
f.r = n
f.x = n
assert k.x.r.r.x.txt == "
class A:
    def __init__(self, txt: str):
        self.r: A = None
        self.x: A = None
        self.txt = txt

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

e = A("e")
k = B("k")
d = B("d")
n = A("n")
h = B("h")
c = A("c")
a = B("a")
b = B("b")
f = A("f")

e.r = n
e.x = f
k.y = b
k.x = c
d.y = k
d.x = n
n.r = c
n.x = f
h.y = d
h.x = e
c.r = n
c.x = f
a.y = b
a.x = f
b.y = h
b.x = n
f.r = n
f.x = n
assert k.x.r.r.x.txt == "f"